-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
derive_tools: IndexMut macros
- Loading branch information
Showing
30 changed files
with
824 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
module/core/derive_tools/tests/inc/index_mut/compiletime/enum.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use derive_tools::IndexMut; | ||
|
||
#[ derive( IndexMut ) ] | ||
enum Enum< T > | ||
{ | ||
Nothing, | ||
#[ index ] | ||
IndexVector( Vec< T > ) | ||
} | ||
|
||
fn main() | ||
{ | ||
} |
7 changes: 7 additions & 0 deletions
7
module/core/derive_tools/tests/inc/index_mut/compiletime/enum.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
error: proc-macro derive panicked | ||
--> tests/inc/index_mut/compiletime/enum.rs:3:12 | ||
| | ||
3 | #[ derive( IndexMut ) ] | ||
| ^^^^^^^^ | ||
| | ||
= help: message: not implemented: IndexMut not implemented for Enum |
14 changes: 14 additions & 0 deletions
14
module/core/derive_tools/tests/inc/index_mut/compiletime/struct.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use derive_tools::IndexMut; | ||
|
||
#[ derive( IndexMut ) ] | ||
struct StructMultipleNamed< T > | ||
{ | ||
#[ index ] | ||
a : Vec< T >, | ||
#[ index ] | ||
b : Vec< T >, | ||
} | ||
|
||
fn main() | ||
{ | ||
} |
8 changes: 8 additions & 0 deletions
8
module/core/derive_tools/tests/inc/index_mut/compiletime/struct.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error: Only one field can include #[ index ] derive macro | ||
--> tests/inc/index_mut/compiletime/struct.rs:6:3 | ||
| | ||
6 | / #[ index ] | ||
7 | | a : Vec< T >, | ||
8 | | #[ index ] | ||
9 | | b : Vec< T >, | ||
| |_______________^ |
10 changes: 10 additions & 0 deletions
10
module/core/derive_tools/tests/inc/index_mut/compiletime/struct_named_empty.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use derive_tools::IndexMut; | ||
|
||
#[ derive( IndexMut ) ] | ||
struct EmptyStruct | ||
{ | ||
} | ||
|
||
fn main() | ||
{ | ||
} |
7 changes: 7 additions & 0 deletions
7
module/core/derive_tools/tests/inc/index_mut/compiletime/struct_named_empty.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
error: proc-macro derive panicked | ||
--> tests/inc/index_mut/compiletime/struct_named_empty.rs:3:12 | ||
| | ||
3 | #[ derive( IndexMut ) ] | ||
| ^^^^^^^^ | ||
| | ||
= help: message: not implemented: IndexMut not implemented for Unit |
9 changes: 9 additions & 0 deletions
9
module/core/derive_tools/tests/inc/index_mut/compiletime/struct_unit.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use derive_tools::IndexMut; | ||
|
||
#[ derive( IndexMut ) ] | ||
struct StructUnit; | ||
|
||
fn main() | ||
{ | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
module/core/derive_tools/tests/inc/index_mut/compiletime/struct_unit.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
error: proc-macro derive panicked | ||
--> tests/inc/index_mut/compiletime/struct_unit.rs:3:12 | ||
| | ||
3 | #[ derive( IndexMut ) ] | ||
| ^^^^^^^^ | ||
| | ||
= help: message: not implemented: IndexMut not implemented for Unit |
20 changes: 20 additions & 0 deletions
20
module/core/derive_tools/tests/inc/index_mut/only_test/struct_multiple_named.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#[ test ] | ||
fn index_mut() | ||
{ | ||
let mut x = StructMultipleNamed | ||
{ | ||
a : vec![ 4, 17 ], | ||
b : vec![ 33, 55 ] | ||
}; | ||
|
||
x[ 0 ] = 5; | ||
x[ 1 ] = 18; | ||
let v = vec![ 5, 18 ]; | ||
|
||
let exp = ( v[ 0 ], v[ 1 ] ); | ||
let got = ( x[ 0 ], x[ 1 ] ); | ||
|
||
assert_eq!( got, exp ); | ||
} | ||
|
||
|
14 changes: 14 additions & 0 deletions
14
module/core/derive_tools/tests/inc/index_mut/only_test/struct_multiple_tuple.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#[ test ] | ||
fn index_mut() | ||
{ | ||
let mut x = StructMultipleTuple( false, vec![ 2, 44, 81 ] ); | ||
|
||
x[ 0 ] = 18; | ||
x[ 1 ] = 99; | ||
|
||
let exp = ( 18, 99 ); | ||
let got = ( x[ 0 ], x[ 1 ] ); | ||
|
||
assert_eq!( got, exp ); | ||
} | ||
|
18 changes: 18 additions & 0 deletions
18
module/core/derive_tools/tests/inc/index_mut/only_test/struct_named.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#[ test ] | ||
fn index_mut() | ||
{ | ||
let mut x = StructNamed | ||
{ | ||
a : vec![ 4, 17 ] | ||
}; | ||
|
||
x[ 0 ] = 5; | ||
x[ 1 ] = 18; | ||
let v = vec![ 5, 18 ]; | ||
|
||
let exp = ( v[ 0 ], v[ 1 ] ); | ||
let got = ( x[ 0 ], x[ 1 ] ); | ||
|
||
assert_eq!( got, exp ); | ||
} | ||
|
14 changes: 14 additions & 0 deletions
14
module/core/derive_tools/tests/inc/index_mut/only_test/struct_tuple.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#[ test ] | ||
fn index_mut() | ||
{ | ||
let mut x = StructTuple( vec![ 2, 44, 81 ] ); | ||
|
||
x[ 0 ] = 18; | ||
x[ 1 ] = 99; | ||
|
||
let exp = ( 18, 99 ); | ||
let got = ( x[ 0 ], x[ 1 ] ); | ||
|
||
assert_eq!( got, exp ); | ||
} | ||
|
22 changes: 22 additions & 0 deletions
22
module/core/derive_tools/tests/inc/index_mut/struct_collisions.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
#![ 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::IndexMut ) ] | ||
#[ allow( dead_code ) ] | ||
struct StructMultipleNamed< T > | ||
{ | ||
a : Vec< T >, | ||
#[ index ] | ||
b : Vec< T >, | ||
} | ||
|
||
include!( "./only_test/struct_multiple_named.rs" ); |
14 changes: 14 additions & 0 deletions
14
module/core/derive_tools/tests/inc/index_mut/struct_multiple_named_field.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#![ allow( dead_code ) ] | ||
#[ allow( unused_imports ) ] | ||
use super::*; | ||
|
||
#[ derive( the_module::IndexMut ) ] | ||
struct StructMultipleNamed< T > | ||
{ | ||
a : Vec< T >, | ||
#[ index ] | ||
b : Vec< T >, | ||
} | ||
|
||
include!( "./only_test/struct_multiple_named.rs" ); | ||
|
15 changes: 15 additions & 0 deletions
15
module/core/derive_tools/tests/inc/index_mut/struct_multiple_named_item.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#![ allow( dead_code ) ] | ||
#[ allow( unused_imports ) ] | ||
use super::*; | ||
|
||
#[ derive( the_module::IndexMut ) ] | ||
#[ index( name = b ) ] | ||
struct StructMultipleNamed< T > | ||
{ | ||
a : Vec< T >, | ||
b : Vec< T >, | ||
} | ||
|
||
include!( "./only_test/struct_multiple_named.rs" ); | ||
|
||
|
30 changes: 30 additions & 0 deletions
30
module/core/derive_tools/tests/inc/index_mut/struct_multiple_named_manual.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use core::ops::{ Index, IndexMut }; | ||
|
||
#[ allow( dead_code ) ] | ||
struct StructMultipleNamed< T > | ||
{ | ||
a : Vec< T >, | ||
b : Vec< T >, | ||
} | ||
|
||
impl< T > Index< usize > for StructMultipleNamed< T > | ||
{ | ||
type Output = T; | ||
|
||
fn index( &self, index : usize ) -> &Self::Output | ||
{ | ||
&self.b[ index ] | ||
} | ||
} | ||
|
||
impl< T > IndexMut< usize > for StructMultipleNamed< T > | ||
{ | ||
fn index_mut( &mut self, index : usize ) -> &mut Self::Output | ||
{ | ||
&mut self.b[ index ] | ||
} | ||
} | ||
|
||
|
||
include!( "./only_test/struct_multiple_named.rs" ); | ||
|
15 changes: 15 additions & 0 deletions
15
module/core/derive_tools/tests/inc/index_mut/struct_multiple_tuple.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#![ allow( dead_code ) ] | ||
#[ allow( unused_imports ) ] | ||
use super::*; | ||
|
||
|
||
#[ derive( the_module::IndexMut ) ] | ||
struct StructMultipleTuple< T > | ||
( | ||
bool, | ||
#[ index ] | ||
Vec< T > | ||
); | ||
|
||
include!( "./only_test/struct_multiple_tuple.rs" ); | ||
|
27 changes: 27 additions & 0 deletions
27
module/core/derive_tools/tests/inc/index_mut/struct_multiple_tuple_manual.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use core::ops::{ Index, IndexMut }; | ||
|
||
#[ allow( dead_code ) ] | ||
struct StructMultipleTuple< T >( bool, Vec< T > ); | ||
|
||
impl< T > Index< usize > for StructMultipleTuple< T > | ||
{ | ||
type Output = T; | ||
|
||
fn index( &self, index : usize ) -> &Self::Output | ||
{ | ||
&self.1[ index ] | ||
} | ||
} | ||
|
||
impl< T > IndexMut< usize > for StructMultipleTuple< T > | ||
{ | ||
fn index_mut( &mut self, index : usize ) -> &mut Self::Output | ||
{ | ||
&mut self.1[ index ] | ||
} | ||
} | ||
|
||
|
||
include!( "./only_test/struct_multiple_tuple.rs" ); | ||
|
||
|
12 changes: 12 additions & 0 deletions
12
module/core/derive_tools/tests/inc/index_mut/struct_named.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#![ allow( dead_code ) ] | ||
#[ allow( unused_imports ) ] | ||
use super::*; | ||
|
||
#[ derive( the_module::IndexMut ) ] | ||
struct StructNamed< T > | ||
{ | ||
#[ index ] | ||
a : Vec< T >, | ||
} | ||
|
||
include!( "./only_test/struct_named.rs" ); |
28 changes: 28 additions & 0 deletions
28
module/core/derive_tools/tests/inc/index_mut/struct_named_manual.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use core::ops::{ Index, IndexMut }; | ||
|
||
#[ allow( dead_code ) ] | ||
struct StructNamed< T > | ||
{ | ||
a : Vec< T > | ||
} | ||
|
||
impl< T > Index< usize > for StructNamed< T > | ||
{ | ||
type Output = T; | ||
|
||
fn index( &self, index : usize ) -> &Self::Output | ||
{ | ||
&self.a[ index ] | ||
} | ||
} | ||
|
||
impl< T > IndexMut< usize > for StructNamed< T > | ||
{ | ||
fn index_mut( &mut self, index : usize ) -> &mut Self::Output | ||
{ | ||
&mut self.a[ index ] | ||
} | ||
} | ||
|
||
|
||
include!( "./only_test/struct_named.rs" ); |
12 changes: 12 additions & 0 deletions
12
module/core/derive_tools/tests/inc/index_mut/struct_tuple.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#![ allow( dead_code ) ] | ||
#[ allow( unused_imports ) ] | ||
use super::*; | ||
|
||
#[ derive( the_module::IndexMut ) ] | ||
struct StructTuple< T > | ||
( | ||
#[ index ] | ||
Vec< T > | ||
); | ||
|
||
include!( "./only_test/struct_tuple.rs" ); |
Oops, something went wrong.