File tree Expand file tree Collapse file tree 8 files changed +40
-33
lines changed Expand file tree Collapse file tree 8 files changed +40
-33
lines changed Original file line number Diff line number Diff line change 1
1
[workspace ]
2
2
members = [
3
3
" dynamic_plan_tree" ,
4
- " dynamic_plan_tree_derive" ,
4
+ " enum_cast" ,
5
+ " enum_cast_derive" ,
5
6
]
Original file line number Diff line number Diff line change @@ -3,10 +3,8 @@ name = "dynamic_plan_tree"
3
3
version = " 0.1.0"
4
4
edition = " 2021"
5
5
6
- # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7
-
8
6
[dependencies ]
9
- dynamic_plan_tree_derive = { path = " ../dynamic_plan_tree_derive " }
7
+ enum_cast = { path = " ../enum_cast " }
10
8
enum_dispatch = " 0.3"
11
9
rayon = { version = " 1.5" , optional = true }
12
10
serde = { version = " 1.0" , features = [" derive" ]}
Original file line number Diff line number Diff line change 1
1
pub use behaviour:: Behaviour ;
2
- pub use dynamic_plan_tree_derive :: EnumCast ;
2
+ pub use enum_cast :: * ;
3
3
pub use enum_dispatch:: enum_dispatch;
4
4
pub use plan:: * ;
5
5
pub use predicate:: Predicate ;
Original file line number Diff line number Diff line change @@ -20,30 +20,6 @@ pub trait Config: Sized + 'static {
20
20
type Behaviour : Behaviour < Self > + Serialize + DeserializeOwned + EnumCast ;
21
21
}
22
22
23
- pub trait EnumRef < T > {
24
- fn enum_ref ( & self ) -> Option < & T > ;
25
- fn enum_mut ( & mut self ) -> Option < & mut T > ;
26
- }
27
-
28
- pub trait EnumCast {
29
- fn cast < T : ' static > ( & self ) -> Option < & T > ;
30
- fn cast_mut < T : ' static > ( & mut self ) -> Option < & mut T > ;
31
- fn from_any < T : ' static > ( t : T ) -> Option < Self >
32
- where
33
- Self : Sized ;
34
- }
35
-
36
- pub trait IntoEnum {
37
- fn into_enum < T : EnumCast > ( self ) -> Option < T >
38
- where
39
- Self : ' static + Sized ,
40
- {
41
- T :: from_any ( self )
42
- }
43
- }
44
-
45
- impl < T > IntoEnum for T { }
46
-
47
23
/// Transition from `src` plans to `dst` plans within the parent plan upon the result of `predicate` evaluation.
48
24
#[ derive( Serialize , Deserialize ) ]
49
25
pub struct Transition < P > {
Original file line number Diff line number Diff line change
1
+ [package ]
2
+ name = " enum_cast"
3
+ version = " 0.1.0"
4
+ edition = " 2021"
5
+
6
+ [dependencies ]
7
+ enum_cast_derive = { path = " ../enum_cast_derive" }
Original file line number Diff line number Diff line change
1
+ pub use enum_cast_derive:: EnumCast ;
2
+
3
+ pub trait EnumRef < T > {
4
+ fn enum_ref ( & self ) -> Option < & T > ;
5
+ fn enum_mut ( & mut self ) -> Option < & mut T > ;
6
+ }
7
+
8
+ pub trait EnumCast {
9
+ fn cast < T : ' static > ( & self ) -> Option < & T > ;
10
+ fn cast_mut < T : ' static > ( & mut self ) -> Option < & mut T > ;
11
+ fn from_any < T : ' static > ( t : T ) -> Option < Self >
12
+ where
13
+ Self : Sized ;
14
+ }
15
+
16
+ pub trait IntoEnum {
17
+ fn into_enum < T : EnumCast > ( self ) -> Option < T >
18
+ where
19
+ Self : ' static + Sized ,
20
+ {
21
+ T :: from_any ( self )
22
+ }
23
+ }
24
+
25
+ impl < T > IntoEnum for T { }
Original file line number Diff line number Diff line change 1
1
[package ]
2
- name = " dynamic_plan_tree_derive "
2
+ name = " enum_cast_derive "
3
3
version = " 0.1.0"
4
4
edition = " 2021"
5
5
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ pub fn enum_cast_derive(input: TokenStream) -> TokenStream {
22
22
23
23
quote ! {
24
24
#(
25
- impl #impl_generics EnumRef <#fields> for #name #ty_generics #where_clause {
25
+ impl #impl_generics enum_cast :: EnumRef <#fields> for #name #ty_generics #where_clause {
26
26
fn enum_ref( & self ) -> Option <& #fields> {
27
27
match self {
28
28
Self :: #idents( x) => Some ( x) ,
@@ -38,7 +38,7 @@ pub fn enum_cast_derive(input: TokenStream) -> TokenStream {
38
38
}
39
39
) *
40
40
41
- impl #impl_generics EnumCast for #name #ty_generics #where_clause {
41
+ impl #impl_generics enum_cast :: EnumCast for #name #ty_generics #where_clause {
42
42
fn cast<T : ' static >( & self ) -> Option <& T > {
43
43
match self {
44
44
#(
@@ -70,7 +70,7 @@ pub fn enum_cast_derive(input: TokenStream) -> TokenStream {
70
70
}
71
71
Data :: Struct ( _) => {
72
72
quote ! {
73
- impl #impl_generics EnumCast for #name #ty_generics #where_clause {
73
+ impl #impl_generics enum_cast :: EnumCast for #name #ty_generics #where_clause {
74
74
fn cast<T : ' static >( & self ) -> Option <& T > {
75
75
( self as & dyn std:: any:: Any ) . downcast_ref:: <T >( )
76
76
}
You can’t perform that action at this time.
0 commit comments