11use facet:: Facet ;
2+ use facet_reflect:: Partial ;
23use num_traits:: { Bounded , FromPrimitive , Num , ToPrimitive } ;
34use serde:: Serialize ;
45use serde:: de:: DeserializeOwned ;
@@ -7,8 +8,6 @@ use std::fmt;
78use std:: ops:: AddAssign ;
89
910use std:: { convert:: TryInto , str:: FromStr } ;
10- use strum:: IntoEnumIterator ;
11- use strum_macros:: { EnumIter , EnumString } ;
1211
1312use super :: serializer:: { FixedSizeKeySerializer , KeySerializer } ;
1413use crate :: serializer:: KeyVec ;
@@ -34,7 +33,9 @@ pub struct AnnoKey {
3433}
3534
3635/// An annotation with a qualified name and a value.
37- #[ derive( Serialize , Deserialize , Default , Eq , PartialEq , PartialOrd , Ord , Clone , Debug , Hash ) ]
36+ #[ derive(
37+ Facet , Serialize , Deserialize , Default , Eq , PartialEq , PartialOrd , Ord , Clone , Debug , Hash ,
38+ ) ]
3839pub struct Annotation {
3940 /// Qualified name or unique "key" for the annotation
4041 pub key : AnnoKey ,
@@ -43,7 +44,9 @@ pub struct Annotation {
4344}
4445
4546/// Directed edge between a source and target node which are identified by their ID.
46- #[ derive( Serialize , Deserialize , Eq , PartialEq , PartialOrd , Ord , Clone , Debug , Hash , Default ) ]
47+ #[ derive(
48+ Facet , Serialize , Deserialize , Eq , PartialEq , PartialOrd , Ord , Clone , Debug , Hash , Default ,
49+ ) ]
4750#[ repr( C ) ]
4851pub struct Edge {
4952 pub source : NodeID ,
@@ -138,7 +141,8 @@ pub trait ComponentType:
138141}
139142
140143/// A simplified implementation of a `ComponentType` that only has one type of edges.
141- #[ derive( Clone , Eq , PartialEq , PartialOrd , Ord , EnumString , EnumIter , Debug ) ]
144+ #[ derive( Facet , Clone , Eq , PartialEq , PartialOrd , Ord , Debug ) ]
145+ #[ repr( u16 ) ]
142146pub enum DefaultComponentType {
143147 Edge ,
144148}
@@ -163,7 +167,7 @@ impl fmt::Display for DefaultComponentType {
163167
164168pub struct DefaultGraphIndex ;
165169
166- #[ derive( Serialize , Deserialize ) ]
170+ #[ derive( Facet , Serialize , Deserialize ) ]
167171pub struct DefaultGlobalStatistics ;
168172
169173impl ComponentType for DefaultComponentType {
@@ -176,15 +180,27 @@ impl ComponentType for DefaultComponentType {
176180 Ok ( DefaultGraphIndex { } )
177181 }
178182 fn all_component_types ( ) -> Vec < Self > {
179- DefaultComponentType :: iter ( ) . collect ( )
183+ vec ! [ DefaultComponentType :: Edge ]
180184 }
181185 fn calculate_global_statistics ( _graph : & mut Graph < Self > ) -> StdResult < ( ) , ComponentTypeError > {
182186 Ok ( ( ) )
183187 }
184188}
185189
190+ impl FromStr for DefaultComponentType {
191+ type Err = GraphAnnisCoreError ;
192+
193+ fn from_str ( s : & str ) -> StdResult < Self , Self :: Err > {
194+ let result = Partial :: alloc_shape ( DefaultComponentType :: SHAPE ) ?
195+ . select_variant_named ( s) ?
196+ . build ( ) ?
197+ . materialize ( ) ?;
198+ Ok ( result)
199+ }
200+ }
201+
186202/// Identifies an edge component of the graph.
187- #[ derive( Serialize , Deserialize , Eq , PartialEq , PartialOrd , Ord , Hash , Clone , Debug ) ]
203+ #[ derive( Facet , Serialize , Deserialize , Eq , PartialEq , PartialOrd , Ord , Hash , Clone , Debug ) ]
188204pub struct Component < CT : ComponentType > {
189205 /// Type of the component
190206 ctype : u16 ,
0 commit comments