Skip to content

Commit

Permalink
READY: Index macros (#1408)
Browse files Browse the repository at this point in the history
derive_tools : Index macros
  • Loading branch information
Inkvisto authored Jul 15, 2024
1 parent 1eaa1ea commit ad8ac94
Show file tree
Hide file tree
Showing 13 changed files with 418 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use derive_tools::Index;
struct StructMultipleNamed< T >
{
#[ index ]
a: Vec< T >,
a : Vec< T >,
#[ index ]
b : Vec< T >,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: Only one field can include #[index] derive macro
error: Only one field can include #[ index ] derive macro
--> tests/inc/index/compiletime/struct.rs:6:3
|
6 | / #[ index ]
7 | | a: Vec< T >,
7 | | a : Vec< T >,
8 | | #[ index ]
9 | | b : Vec< T >,
| |_______________^
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ fn index()
{
let x = StructMultipleNamed
{
a: vec![ 12, 22 ],
b: vec![ 33, 55 ]
a : vec![ 12, 22 ],
b : vec![ 33, 55 ]
};
let v = vec![ 33, 55 ];
let exp = ( v[ 0 ], v[ 1 ] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ fn index()
{
let x = StructNamed
{
a: vec![ false, true ]
a : vec![ false, true ]
};
let v = vec![ false, true ];
let exp = ( v[ 0 ], v[ 1 ] );
Expand Down
23 changes: 23 additions & 0 deletions module/core/derive_tools/tests/inc/index/struct_collisions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#![ allow( non_snake_case ) ]
#![ allow( unused_imports ) ]
use super::*;

pub mod core {}
pub mod std {}
pub mod marker {}

pub mod a {}
pub mod b {}

#[ derive( the_module::Index, the_module::From ) ]
#[ allow( dead_code ) ]
struct StructMultipleNamed< T >
{
#[ from ( on ) ]
a : Vec< T >,
#[ index ]
b : Vec< T >,
}

include!( "./only_test/struct_multiple_named.rs" );

Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ struct StructMultipleNamed< T >
}

include!( "./only_test/struct_multiple_named.rs" );

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![ allow( dead_code ) ]
#[ allow( unused_imports ) ]
use super::*;

#[ derive( the_module::Index ) ]
#[ index ( name = b ) ]
struct StructMultipleNamed< T >
{
a : Vec< T >,
b : Vec< T >,
}

include!( "./only_test/struct_multiple_named.rs" );
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use core::ops::Index;
#[ allow( dead_code ) ]
struct StructMultipleNamed< T >
{
a: Vec< T >,
b: Vec< T >,
a : Vec< T >,
b : Vec< T >,
}

impl< T > Index< usize > for StructMultipleNamed< T >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::ops::Index;
#[ allow( dead_code ) ]
struct StructNamed< T >
{
a: Vec< T >
a : Vec< T >
}

impl< T > Index< usize > for StructNamed< T >
Expand Down
8 changes: 5 additions & 3 deletions module/core/derive_tools/tests/inc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,17 @@ mod index_tests
#[ allow( unused_imports ) ]
use super::*;

mod struct_named;
mod struct_multiple_named;
mod struct_named;
mod struct_multiple_named_field;
mod struct_multiple_named_item;
mod struct_named_manual;
mod struct_multiple_named_manual;
mod struct_tuple;
mod struct_multiple_tuple;
mod struct_tuple_manual;
mod struct_multiple_tuple_manual;

mod struct_collisions;

only_for_terminal_module!
{
#[ test_tools::nightly ]
Expand Down
Loading

0 comments on commit ad8ac94

Please sign in to comment.