Skip to content

Commit

Permalink
Merge pull request #1305 from YBoy-git/derive_deref
Browse files Browse the repository at this point in the history
READY : (derive_tools) : derive_deref & derive_deref_mut implementation improvement & tests extension & From docs
  • Loading branch information
Wandalen authored Jun 1, 2024
2 parents a36cbfa + dc7c9de commit e93f2f7
Show file tree
Hide file tree
Showing 107 changed files with 2,696 additions and 92 deletions.
10 changes: 10 additions & 0 deletions module/core/derive_tools/tests/inc/deref/bounds_inlined.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use core::fmt::Debug;

use core::ops::Deref;
use derive_tools::Deref;

#[ allow( dead_code ) ]
#[ derive( Deref ) ]
struct BoundsInlined< T : ToString, U : Debug >( T, U );

include!( "./only_tests/bounds_inlined.rs" );
17 changes: 17 additions & 0 deletions module/core/derive_tools/tests/inc/deref/bounds_inlined_manual.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use core::fmt::Debug;

use core::ops::Deref;

#[ allow( dead_code ) ]
struct BoundsInlined< T : ToString, U : Debug >( T, U );

impl< T : ToString, U : Debug > Deref for BoundsInlined< T, U >
{
type Target = T;
fn deref( &self ) -> &Self::Target
{
&self.0
}
}

include!( "./only_tests/bounds_inlined.rs" );
12 changes: 12 additions & 0 deletions module/core/derive_tools/tests/inc/deref/bounds_mixed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use core::fmt::Debug;

use core::ops::Deref;
use derive_tools::Deref;

#[ allow( dead_code ) ]
#[ derive( Deref ) ]
struct BoundsMixed< T : ToString, U >( T, U )
where
U : Debug;

include!( "./only_tests/bounds_mixed.rs" );
21 changes: 21 additions & 0 deletions module/core/derive_tools/tests/inc/deref/bounds_mixed_manual.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use core::fmt::Debug;

use core::ops::Deref;

#[ allow( dead_code ) ]
struct BoundsMixed< T : ToString, U >( T, U )
where
U : Debug;

impl< T : ToString, U > Deref for BoundsMixed< T, U >
where
U : Debug,
{
type Target = T;
fn deref( &self ) -> &Self::Target
{
&self.0
}
}

include!( "./only_tests/bounds_mixed.rs" );
14 changes: 14 additions & 0 deletions module/core/derive_tools/tests/inc/deref/bounds_where.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
trait Trait<'a> {}
impl<'a> Trait<'a> for i32 {}

use core::ops::Deref;
use derive_tools::Deref;

#[ allow( dead_code ) ]
#[ derive( Deref ) ]
struct BoundsWhere< T, U >( T, U )
where
T : ToString,
for< 'a > U : Trait< 'a >;

include!( "./only_tests/bounds_where.rs" );
24 changes: 24 additions & 0 deletions module/core/derive_tools/tests/inc/deref/bounds_where_manual.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
trait Trait<'a> {}
impl<'a> Trait<'a> for i32 {}

use core::ops::Deref;

#[ allow( dead_code ) ]
struct BoundsWhere< T, U >( T, U )
where
T : ToString,
for< 'a > U : Trait< 'a >;

impl< T, U > Deref for BoundsWhere< T, U >
where
T : ToString,
for< 'a > U : Trait< 'a >
{
type Target = T;
fn deref( &self ) -> &Self::Target
{
&self.0
}
}

include!( "./only_tests/bounds_where.rs" );
12 changes: 12 additions & 0 deletions module/core/derive_tools/tests/inc/deref/enum_named.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use core::ops::Deref;
use derive_tools::Deref;

#[ allow( dead_code) ]
#[ derive( Deref ) ]
enum EnumNamed
{
A { a : String, b : i32 },
B { a : String, b : i32 },
}

include!( "./only_tests/enum_named.rs" );
12 changes: 12 additions & 0 deletions module/core/derive_tools/tests/inc/deref/enum_named_empty.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use core::ops::Deref;
use derive_tools::Deref;

#[ allow( dead_code) ]
#[ derive( Deref ) ]
enum EnumNamedEmpty
{
A {},
B {},
}

include!( "./only_tests/enum_named_empty.rs" );
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use core::ops::Deref;

#[ allow( dead_code) ]
enum EnumNamedEmpty
{
A {},
B {},
}

impl Deref for EnumNamedEmpty
{
type Target = ();
fn deref( &self ) -> &Self::Target
{
&()
}
}

include!( "./only_tests/enum_named_empty.rs" );
22 changes: 22 additions & 0 deletions module/core/derive_tools/tests/inc/deref/enum_named_manual.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use core::ops::Deref;

#[ allow( dead_code) ]
enum EnumNamed
{
A { a : String, b : i32 },
B { a : String, b : i32 },
}

impl Deref for EnumNamed
{
type Target = String;
fn deref( &self ) -> &Self::Target
{
match self
{
Self::A { a : v, ..} | Self::B { a : v, .. } => v
}
}
}

include!( "./only_tests/enum_named.rs" );
12 changes: 12 additions & 0 deletions module/core/derive_tools/tests/inc/deref/enum_tuple.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use core::ops::Deref;
use derive_tools::Deref;

#[ allow( dead_code) ]
#[ derive( Deref ) ]
enum EnumTuple
{
A( String, i32 ),
B( String, i32 ),
}

include!( "./only_tests/enum_tuple.rs" );
12 changes: 12 additions & 0 deletions module/core/derive_tools/tests/inc/deref/enum_tuple_empty.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use core::ops::Deref;
use derive_tools::Deref;

#[ allow( dead_code) ]
#[ derive( Deref ) ]
enum EnumTupleEmpty
{
A(),
B(),
}

include!( "./only_tests/enum_tuple_empty.rs" );
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use core::ops::Deref;

#[ allow( dead_code) ]
enum EnumTupleEmpty
{
A(),
B(),
}

impl Deref for EnumTupleEmpty
{
type Target = ();
fn deref( &self ) -> &Self::Target
{
&()
}
}

include!( "./only_tests/enum_tuple_empty.rs" );
22 changes: 22 additions & 0 deletions module/core/derive_tools/tests/inc/deref/enum_tuple_manual.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use core::ops::Deref;

#[ allow( dead_code) ]
enum EnumTuple
{
A( String, i32 ),
B( String, i32 ),
}

impl Deref for EnumTuple
{
type Target = String;
fn deref( &self ) -> &Self::Target
{
match self
{
Self::A( v, .. ) | Self::B( v, .. ) => v
}
}
}

include!( "./only_tests/enum_tuple.rs" );
12 changes: 12 additions & 0 deletions module/core/derive_tools/tests/inc/deref/enum_unit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use core::ops::Deref;
use derive_tools::Deref;

#[ allow( dead_code) ]
#[ derive( Deref ) ]
enum EnumUnit
{
A,
B,
}

include!( "./only_tests/enum_unit.rs" );
19 changes: 19 additions & 0 deletions module/core/derive_tools/tests/inc/deref/enum_unit_manual.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use core::ops::Deref;

#[ allow( dead_code) ]
enum EnumUnit
{
A,
B,
}

impl Deref for EnumUnit
{
type Target = ();
fn deref( &self ) -> &Self::Target
{
&()
}
}

include!( "./only_tests/enum_unit.rs" );
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use core::ops::Deref;
use derive_tools::Deref;

#[ allow( dead_code ) ]
#[ derive( Deref ) ]
struct GenericsConstants< const N : usize >( i32 );

include!( "./only_tests/generics_constants.rs" );
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use core::ops::Deref;
use derive_tools::Deref;

#[ allow( dead_code ) ]
#[ derive( Deref ) ]
struct GenericsConstantsDefault< const N : usize = 0 >( i32 );

include!( "./only_tests/generics_constants_default.rs" );
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use core::ops::Deref;

#[ allow( dead_code ) ]
struct GenericsConstantsDefault< const N : usize = 0 >( i32 );

impl< const N : usize > Deref for GenericsConstantsDefault< N >
{
type Target = i32;
fn deref( &self ) -> &Self::Target
{
&self.0
}
}

include!( "./only_tests/generics_constants_default.rs" );
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use core::ops::Deref;

#[ allow( dead_code ) ]
struct GenericsConstants< const N : usize >( i32 );

impl< const N : usize > Deref for GenericsConstants< N >
{
type Target = i32;
fn deref( &self ) -> &Self::Target
{
&self.0
}
}

include!( "./only_tests/generics_constants.rs" );
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use core::ops::Deref;
use derive_tools::Deref;

#[ allow( dead_code ) ]
#[ derive( Deref ) ]
struct GenericsLifetimes< 'a >( &'a i32 );

include!( "./only_tests/generics_lifetimes.rs" );
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use core::ops::Deref;

#[ allow( dead_code ) ]
struct GenericsLifetimes< 'a >( &'a i32 );

impl< 'a > Deref for GenericsLifetimes< 'a >
{
type Target = &'a i32;
fn deref( &self ) -> &Self::Target
{
&self.0
}
}

include!( "./only_tests/generics_lifetimes.rs" );
8 changes: 8 additions & 0 deletions module/core/derive_tools/tests/inc/deref/generics_types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use core::ops::Deref;
use derive_tools::Deref;

#[ allow( dead_code ) ]
#[ derive( Deref ) ]
struct GenericsTypes< T >( T );

include!( "./only_tests/generics_types.rs" );
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use core::ops::Deref;
use derive_tools::Deref;

#[ allow( dead_code ) ]
#[ derive ( Deref ) ]
struct GenericsTypesDefault< T = i32 >( T );

include!( "./only_tests/generics_types_default.rs" );
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use core::ops::Deref;

#[ allow( dead_code ) ]
struct GenericsTypesDefault< T = i32 >( T );

impl< T > Deref for GenericsTypesDefault< T >
{
type Target = T;
fn deref( &self ) -> &Self::Target
{
&self.0
}
}

include!( "./only_tests/generics_types_default.rs" );
15 changes: 15 additions & 0 deletions module/core/derive_tools/tests/inc/deref/generics_types_manual.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use core::ops::Deref;

#[ allow( dead_code ) ]
struct GenericsTypes< T >( T );

impl< T > Deref for GenericsTypes< T >
{
type Target = T;
fn deref( &self ) -> &Self::Target
{
&self.0
}
}

include!( "./only_tests/generics_types.rs" );
Loading

0 comments on commit e93f2f7

Please sign in to comment.