@@ -170,23 +170,51 @@ pub struct MemoryRegion {
170170impl < T > Result < T > {
171171 /// Obtain the inner value, or panic - just like `core::Result::unwrap`.
172172 pub fn unwrap ( self ) -> T {
173- match self {
174- crate :: Result :: Ok ( val) => val,
175- crate :: Result :: Err ( e) => {
176- panic ! ( "Unwrap called, got err {:?}" , e) ;
177- }
173+ let r: core:: result:: Result < T , Error > = self . into ( ) ;
174+ r. unwrap ( )
175+ }
176+ }
177+
178+ impl < T > From < core:: result:: Result < T , Error > > for Result < T > {
179+ fn from ( value : core:: result:: Result < T , Error > ) -> Self {
180+ match value {
181+ Ok ( inner) => Result :: Ok ( inner) ,
182+ Err ( inner) => Result :: Err ( inner) ,
183+ }
184+ }
185+ }
186+
187+ impl < T > From < Result < T > > for core:: result:: Result < T , Error > {
188+ fn from ( value : Result < T > ) -> Self {
189+ match value {
190+ Result :: Ok ( inner) => core:: result:: Result :: Ok ( inner) ,
191+ Result :: Err ( inner) => core:: result:: Result :: Err ( inner) ,
178192 }
179193 }
180194}
181195
182196impl < T > Option < T > {
183197 /// Obtain the inner value, or panic - just like `core::Option::unwrap`.
184198 pub fn unwrap ( self ) -> T {
185- match self {
186- crate :: Option :: Some ( val) => val,
187- crate :: Option :: None => {
188- panic ! ( "Unwrap called on empty option" ) ;
189- }
199+ let o: core:: option:: Option < T > = self . into ( ) ;
200+ o. unwrap ( )
201+ }
202+ }
203+
204+ impl < T > From < core:: option:: Option < T > > for Option < T > {
205+ fn from ( value : core:: option:: Option < T > ) -> Self {
206+ match value {
207+ Some ( inner) => Option :: Some ( inner) ,
208+ None => Option :: None ,
209+ }
210+ }
211+ }
212+
213+ impl < T > From < Option < T > > for core:: option:: Option < T > {
214+ fn from ( value : Option < T > ) -> Self {
215+ match value {
216+ Option :: Some ( inner) => core:: option:: Option :: Some ( inner) ,
217+ Option :: None => core:: option:: Option :: None ,
190218 }
191219 }
192220}
0 commit comments