Skip to content

Commit

Permalink
derive_tools : from for variants : initial test
Browse files Browse the repository at this point in the history
  • Loading branch information
Wandalen committed May 14, 2024
1 parent 1c14fe3 commit 9806451
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
27 changes: 27 additions & 0 deletions module/core/derive_tools/tests/inc/from_inner_variants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

#[ derive( Debug, PartialEq ) ]
pub enum GetData
{
FromString( String ),
FromBin( &'static [ u8 ] ),
}

impl From< String > for GetData
{
#[ inline ]
fn from( src : String ) -> Self
{
Self::FromString( src )
}
}

impl From< &'static [ u8 ] > for GetData
{
#[ inline ]
fn from( src : &'static [ u8 ] ) -> Self
{
Self::FromBin( src )
}
}

include!( "./only_test/from_inner_variants.rs" );
2 changes: 2 additions & 0 deletions module/core/derive_tools/tests/inc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ mod from_inner_multiple_named_test;
mod from_inner_unit_test;
#[ cfg( feature = "derive_from" ) ]
mod from_inner_multiple_test;
#[ cfg( feature = "derive_from" ) ]
mod from_inner_variants;

mod inner_from_manual_test;
mod inner_from_named_manual_test;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use super::*;

#[ test ]
fn from_inner_named()
{

let got : GetData = From::from( "abc".to_string() );
let exp = GetData::FromString( "abc".to_string() );
a_id!( got, exp );

let got : GetData = From::from( &b"abc"[ .. ] );
let exp = GetData::FromBin( b"abc" );
a_id!( got, exp );

}

0 comments on commit 9806451

Please sign in to comment.