@@ -419,6 +419,45 @@ mod extension {
419419 }
420420}
421421
422+ #[ cfg( feature = "wasi" ) ]
423+ impl From < Method > for wasi:: http:: types:: Method {
424+ fn from ( method : Method ) -> Self {
425+ match method {
426+ Method ( Get ) => Self :: Get ,
427+ Method ( Head ) => Self :: Head ,
428+ Method ( Post ) => Self :: Post ,
429+ Method ( Put ) => Self :: Put ,
430+ Method ( Delete ) => Self :: Delete ,
431+ Method ( Connect ) => Self :: Connect ,
432+ Method ( Options ) => Self :: Options ,
433+ Method ( Trace ) => Self :: Trace ,
434+ Method ( Patch ) => Self :: Patch ,
435+ Method ( ExtensionInline ( inline) ) => Self :: Other ( inline. as_str ( ) . into ( ) ) ,
436+ Method ( ExtensionAllocated ( allocated) ) => Self :: Other ( allocated. as_str ( ) . into ( ) ) ,
437+ }
438+ }
439+ }
440+
441+ #[ cfg( feature = "wasi" ) ]
442+ impl TryFrom < wasi:: http:: types:: Method > for Method {
443+ type Error = InvalidMethod ;
444+
445+ fn try_from ( method : wasi:: http:: types:: Method ) -> Result < Self , Self :: Error > {
446+ match method {
447+ wasi:: http:: types:: Method :: Get => Ok ( Self :: GET ) ,
448+ wasi:: http:: types:: Method :: Head => Ok ( Self :: HEAD ) ,
449+ wasi:: http:: types:: Method :: Post => Ok ( Self :: POST ) ,
450+ wasi:: http:: types:: Method :: Put => Ok ( Self :: PUT ) ,
451+ wasi:: http:: types:: Method :: Delete => Ok ( Self :: DELETE ) ,
452+ wasi:: http:: types:: Method :: Connect => Ok ( Self :: CONNECT ) ,
453+ wasi:: http:: types:: Method :: Options => Ok ( Self :: OPTIONS ) ,
454+ wasi:: http:: types:: Method :: Trace => Ok ( Self :: TRACE ) ,
455+ wasi:: http:: types:: Method :: Patch => Ok ( Self :: PATCH ) ,
456+ wasi:: http:: types:: Method :: Other ( method) => method. parse ( ) ,
457+ }
458+ }
459+ }
460+
422461#[ cfg( test) ]
423462mod test {
424463 use super :: * ;
@@ -482,4 +521,18 @@ mod test {
482521 ) ;
483522 }
484523 }
524+
525+ #[ cfg( feature = "wasi" ) ]
526+ #[ test]
527+ fn test_method_wasi_conv ( ) {
528+ use std:: convert:: TryInto ;
529+
530+ let m: Method = wasi:: http:: types:: Method :: Get
531+ . try_into ( )
532+ . expect ( "failed to convert WASI method" ) ;
533+ assert_eq ! ( m, Method :: GET ) ;
534+
535+ let m: wasi:: http:: types:: Method = Method :: GET . into ( ) ;
536+ assert ! ( matches!( m, wasi:: http:: types:: Method :: Get ) ) ;
537+ }
485538}
0 commit comments