Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Reflection for isize and usize #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion reflection/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "reflection"
version = "0.1.3"
version = "0.1.4"
authors = ["oooutlk <[email protected]>"]
license = "MIT"
keywords = [ "reflect", "reflection", "type", "schema", "tree" ]
Expand Down
34 changes: 18 additions & 16 deletions reflection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub type Name = Option<String>;
pub enum Type {
Unknown,
Struct, Enum,
Bool, I8, U8, I16, U16, I32, U32, I64, U64, I128, U128, F32, F64,
Bool, I8, U8, I16, U16, I32, U32, I64, U64, I128, U128, ISize, USize, F32, F64,
Range,
RefStr, String,
Array, Tuple, Vec,
Expand Down Expand Up @@ -55,10 +55,10 @@ impl PartialOrd for Type {

impl Display for Type { fn fmt( &self, f: &mut Formatter ) -> fmt::Result { write!( f, "{}", TYPE_STR[ *self as usize ])}}

const TYPE_STR: [Id;35] = [
const TYPE_STR: [Id;37] = [
"?",
"struct", "enum",
"bool", "i8", "u8", "i16", "u16", "i32", "u32", "i64", "u64", "i128", "u128", "f32", "f64",
"bool", "i8", "u8", "i16", "u16", "i32", "u32", "i64", "u64", "i128", "u128", "isize", "usize", "f32", "f64",
"Range",
"&str", "String",
"[]", "()", "Vec",
Expand Down Expand Up @@ -206,19 +206,21 @@ macro_rules! expander {
($ty:ty) => { Some( <$ty as Reflection>::members )}
}

impl Reflection for bool { fn ty() -> Type { Type::Bool } fn schema( id: Id ) -> Schema { terminal( id, Type::Bool )}}
impl Reflection for i8 { fn ty() -> Type { Type::I8 } fn schema( id: Id ) -> Schema { terminal( id, Type::I8 )}}
impl Reflection for u8 { fn ty() -> Type { Type::U8 } fn schema( id: Id ) -> Schema { terminal( id, Type::U8 )}}
impl Reflection for i16 { fn ty() -> Type { Type::I16 } fn schema( id: Id ) -> Schema { terminal( id, Type::I16 )}}
impl Reflection for u16 { fn ty() -> Type { Type::U16 } fn schema( id: Id ) -> Schema { terminal( id, Type::U16 )}}
impl Reflection for i32 { fn ty() -> Type { Type::I32 } fn schema( id: Id ) -> Schema { terminal( id, Type::I32 )}}
impl Reflection for u32 { fn ty() -> Type { Type::U32 } fn schema( id: Id ) -> Schema { terminal( id, Type::U32 )}}
impl Reflection for i64 { fn ty() -> Type { Type::I64 } fn schema( id: Id ) -> Schema { terminal( id, Type::I64 )}}
impl Reflection for u64 { fn ty() -> Type { Type::U64 } fn schema( id: Id ) -> Schema { terminal( id, Type::U64 )}}
impl Reflection for i128 { fn ty() -> Type { Type::I128 } fn schema( id: Id ) -> Schema { terminal( id, Type::I128 )}}
impl Reflection for u128 { fn ty() -> Type { Type::U128 } fn schema( id: Id ) -> Schema { terminal( id, Type::U128 )}}
impl Reflection for f32 { fn ty() -> Type { Type::F32 } fn schema( id: Id ) -> Schema { terminal( id, Type::F32 )}}
impl Reflection for f64 { fn ty() -> Type { Type::F64 } fn schema( id: Id ) -> Schema { terminal( id, Type::F64 )}}
impl Reflection for bool { fn ty() -> Type { Type::Bool } fn schema( id: Id ) -> Schema { terminal( id, Type::Bool )}}
impl Reflection for i8 { fn ty() -> Type { Type::I8 } fn schema( id: Id ) -> Schema { terminal( id, Type::I8 )}}
impl Reflection for u8 { fn ty() -> Type { Type::U8 } fn schema( id: Id ) -> Schema { terminal( id, Type::U8 )}}
impl Reflection for i16 { fn ty() -> Type { Type::I16 } fn schema( id: Id ) -> Schema { terminal( id, Type::I16 )}}
impl Reflection for u16 { fn ty() -> Type { Type::U16 } fn schema( id: Id ) -> Schema { terminal( id, Type::U16 )}}
impl Reflection for i32 { fn ty() -> Type { Type::I32 } fn schema( id: Id ) -> Schema { terminal( id, Type::I32 )}}
impl Reflection for u32 { fn ty() -> Type { Type::U32 } fn schema( id: Id ) -> Schema { terminal( id, Type::U32 )}}
impl Reflection for i64 { fn ty() -> Type { Type::I64 } fn schema( id: Id ) -> Schema { terminal( id, Type::I64 )}}
impl Reflection for u64 { fn ty() -> Type { Type::U64 } fn schema( id: Id ) -> Schema { terminal( id, Type::U64 )}}
impl Reflection for i128 { fn ty() -> Type { Type::I128 } fn schema( id: Id ) -> Schema { terminal( id, Type::I128 )}}
impl Reflection for u128 { fn ty() -> Type { Type::U128 } fn schema( id: Id ) -> Schema { terminal( id, Type::U128 )}}
impl Reflection for isize { fn ty() -> Type { Type::ISize } fn schema( id: Id ) -> Schema { terminal( id, Type::ISize )}}
impl Reflection for usize { fn ty() -> Type { Type::USize } fn schema( id: Id ) -> Schema { terminal( id, Type::USize )}}
impl Reflection for f32 { fn ty() -> Type { Type::F32 } fn schema( id: Id ) -> Schema { terminal( id, Type::F32 )}}
impl Reflection for f64 { fn ty() -> Type { Type::F64 } fn schema( id: Id ) -> Schema { terminal( id, Type::F64 )}}

impl<T:Reflection> Reflection for std::ops::Range<T> {
fn ty() -> Type { Type::Range }
Expand Down
2 changes: 1 addition & 1 deletion reflection_test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "reflection_test"
version = "0.1.0"
version = "0.1.1"
authors = ["oooutlk <[email protected]>"]
publish = false

Expand Down
8 changes: 4 additions & 4 deletions reflection_test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ struct SS0( S0 );

#[derive( Reflection )]
struct S1<'a> {
bool_:bool, i8_:i8, u8_:u8, i16_:i16, u16_:u16, i32_:i32, u32_:u32, i64_:i64, u64_:u64, f32_:f32, f64_:f64, str_:&'a str, string:String
bool_:bool, i8_:i8, u8_:u8, i16_:i16, u16_:u16, i32_:i32, u32_:u32, i64_:i64, u64_:u64, isize_:isize, usize_:usize, f32_:f32, f64_:f64, str_:&'a str, string:String
}

#[derive( Reflection )]
struct St1<'a> ( bool, i8, u8, i16, u16, i32, u32, i64, u64, f32, f64, &'a str, String );
struct St1<'a> ( bool, i8, u8, i16, u16, i32, u32, i64, u64, isize, usize, f32, f64, &'a str, String );

#[derive( Reflection )]
struct SS1<'a>( S1<'a> );
Expand Down Expand Up @@ -103,8 +103,8 @@ enum TrippleU32s {
fn misc() {
assert_eq!( S0::schemata().to_string(), "_:S0" );
assert_eq!( SS0::schemata().to_string(), "_:SS0( 0:S0 )" );
assert_eq!( S1::schemata().to_string(), "_:S1( bool_:bool i8_:i8 u8_:u8 i16_:i16 u16_:u16 i32_:i32 u32_:u32 i64_:i64 u64_:u64 f32_:f32 f64_:f64 str_:&str string:String )" );
assert_eq!( St1::schemata().to_string(), "_:St1( 0:bool 1:i8 2:u8 3:i16 4:u16 5:i32 6:u32 7:i64 8:u64 9:f32 10:f64 11:&str 12:String )" );
assert_eq!( S1::schemata().to_string(), "_:S1( bool_:bool i8_:i8 u8_:u8 i16_:i16 u16_:u16 i32_:i32 u32_:u32 i64_:i64 u64_:u64 isize_:isize usize_:usize f32_:f32 f64_:f64 str_:&str string:String )" );
assert_eq!( St1::schemata().to_string(), "_:St1( 0:bool 1:i8 2:u8 3:i16 4:u16 5:i32 6:u32 7:i64 8:u64 9:isize 10:usize 11:f32 12:f64 13:&str 14:String )" );
assert_eq!( SString::schemata().to_string(), "_:SString( 0:String )" );
assert_eq!( EEE::schemata().to_string(), "_:EEE( UUU|( 0:(((),),)( 0:((),)( 0:() ) ) ) )" );
assert_eq!( Color::schemata().to_string(), "_:Color( 0:u32 1:u32 2:u32 )" );
Expand Down