From bd818812c3a1d292e7f0fb4e7eb7cd6f899e7d96 Mon Sep 17 00:00:00 2001 From: Edoardo Morandi Date: Mon, 7 Jan 2019 12:35:56 +0100 Subject: [PATCH] Added Reflection for isize and usize --- reflection/Cargo.toml | 2 +- reflection/src/lib.rs | 34 ++++++++++++++++++---------------- reflection_test/Cargo.toml | 2 +- reflection_test/src/lib.rs | 8 ++++---- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/reflection/Cargo.toml b/reflection/Cargo.toml index 48c2649..b63e123 100644 --- a/reflection/Cargo.toml +++ b/reflection/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "reflection" -version = "0.1.3" +version = "0.1.4" authors = ["oooutlk "] license = "MIT" keywords = [ "reflect", "reflection", "type", "schema", "tree" ] diff --git a/reflection/src/lib.rs b/reflection/src/lib.rs index 4363a11..be54ac4 100644 --- a/reflection/src/lib.rs +++ b/reflection/src/lib.rs @@ -22,7 +22,7 @@ pub type Name = Option; 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, @@ -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", @@ -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 Reflection for std::ops::Range { fn ty() -> Type { Type::Range } diff --git a/reflection_test/Cargo.toml b/reflection_test/Cargo.toml index e8d1b9f..35c336e 100644 --- a/reflection_test/Cargo.toml +++ b/reflection_test/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "reflection_test" -version = "0.1.0" +version = "0.1.1" authors = ["oooutlk "] publish = false diff --git a/reflection_test/src/lib.rs b/reflection_test/src/lib.rs index 3d1c9cc..a2e2cf3 100644 --- a/reflection_test/src/lib.rs +++ b/reflection_test/src/lib.rs @@ -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> ); @@ -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 )" );