pub struct EnumKeyPath<Enum = (), Variant = (), ExtractFn = fn(&()) -> Option<&()>, EmbedFn = fn(())>where
ExtractFn: for<'r> Fn(&'r Enum) -> Option<&'r Variant> + 'static,
EmbedFn: Fn(Variant) -> Enum + 'static,{ /* private fields */ }Expand description
EnumKeyPath - A keypath for enum variants that supports both extraction and embedding Uses generic type parameters instead of dynamic dispatch for zero-cost abstraction
This struct serves dual purpose:
- As a concrete keypath instance:
EnumKeyPath<Enum, Variant, ExtractFn, EmbedFn> - As a namespace for static factory methods:
EnumKeyPath::readable_enum(...)
Implementations§
Source§impl<Enum, Variant, ExtractFn, EmbedFn> EnumKeyPath<Enum, Variant, ExtractFn, EmbedFn>where
ExtractFn: for<'r> Fn(&'r Enum) -> Option<&'r Variant> + 'static,
EmbedFn: Fn(Variant) -> Enum + 'static,
impl<Enum, Variant, ExtractFn, EmbedFn> EnumKeyPath<Enum, Variant, ExtractFn, EmbedFn>where
ExtractFn: for<'r> Fn(&'r Enum) -> Option<&'r Variant> + 'static,
EmbedFn: Fn(Variant) -> Enum + 'static,
Sourcepub fn new(
extractor: ExtractFn,
embedder: EmbedFn,
) -> EnumKeyPath<Enum, Variant, ExtractFn, EmbedFn>
pub fn new( extractor: ExtractFn, embedder: EmbedFn, ) -> EnumKeyPath<Enum, Variant, ExtractFn, EmbedFn>
Create a new EnumKeyPath with extractor and embedder functions
Sourcepub fn get<'r>(&self, enum_value: &'r Enum) -> Option<&'r Variant>
pub fn get<'r>(&self, enum_value: &'r Enum) -> Option<&'r Variant>
Extract the value from an enum variant
Sourcepub fn as_optional(&self) -> &OptionalKeyPath<Enum, Variant, ExtractFn>
pub fn as_optional(&self) -> &OptionalKeyPath<Enum, Variant, ExtractFn>
Get the underlying OptionalKeyPath for composition
Sourcepub fn to_optional(self) -> OptionalKeyPath<Enum, Variant, ExtractFn>
pub fn to_optional(self) -> OptionalKeyPath<Enum, Variant, ExtractFn>
Convert to OptionalKeyPath (loses embedding capability but gains composition)
Source§impl EnumKeyPath
impl EnumKeyPath
Sourcepub fn readable_enum<Enum, Variant, ExtractFn, EmbedFn>(
embedder: EmbedFn,
extractor: ExtractFn,
) -> EnumKeyPath<Enum, Variant, ExtractFn, EmbedFn>where
ExtractFn: for<'r> Fn(&'r Enum) -> Option<&'r Variant> + 'static,
EmbedFn: Fn(Variant) -> Enum + 'static,
pub fn readable_enum<Enum, Variant, ExtractFn, EmbedFn>(
embedder: EmbedFn,
extractor: ExtractFn,
) -> EnumKeyPath<Enum, Variant, ExtractFn, EmbedFn>where
ExtractFn: for<'r> Fn(&'r Enum) -> Option<&'r Variant> + 'static,
EmbedFn: Fn(Variant) -> Enum + 'static,
Create a readable enum keypath with both extraction and embedding Returns an EnumKeyPath that supports both get() and embed() operations
Sourcepub fn for_variant<Enum, Variant, ExtractFn>(
extractor: ExtractFn,
) -> OptionalKeyPath<Enum, Variant, impl for<'r> Fn(&'r Enum)>
pub fn for_variant<Enum, Variant, ExtractFn>( extractor: ExtractFn, ) -> OptionalKeyPath<Enum, Variant, impl for<'r> Fn(&'r Enum)>
Extract from a specific enum variant
Sourcepub fn for_match<Enum, Output, MatchFn>(
matcher: MatchFn,
) -> KeyPath<Enum, Output, impl for<'r> Fn(&'r Enum)>
pub fn for_match<Enum, Output, MatchFn>( matcher: MatchFn, ) -> KeyPath<Enum, Output, impl for<'r> Fn(&'r Enum)>
Match against multiple variants (returns a tagged union)
Sourcepub fn for_ok<T, E>() -> OptionalKeyPath<Result<T, E>, T, impl for<'r> Fn(&'r Result<T, E>)>
pub fn for_ok<T, E>() -> OptionalKeyPath<Result<T, E>, T, impl for<'r> Fn(&'r Result<T, E>)>
Extract from Result<T, E> - Ok variant
Sourcepub fn for_err<T, E>() -> OptionalKeyPath<Result<T, E>, E, impl for<'r> Fn(&'r Result<T, E>)>
pub fn for_err<T, E>() -> OptionalKeyPath<Result<T, E>, E, impl for<'r> Fn(&'r Result<T, E>)>
Extract from Result<T, E> - Err variant
Sourcepub fn for_some<T>() -> OptionalKeyPath<Option<T>, T, impl for<'r> Fn(&'r Option<T>)>
pub fn for_some<T>() -> OptionalKeyPath<Option<T>, T, impl for<'r> Fn(&'r Option<T>)>
Extract from Option
Sourcepub fn for_option<T>() -> OptionalKeyPath<Option<T>, T, impl for<'r> Fn(&'r Option<T>)>
pub fn for_option<T>() -> OptionalKeyPath<Option<T>, T, impl for<'r> Fn(&'r Option<T>)>
Extract from Option
Sourcepub fn for_box_mut<T>() -> WritableKeyPath<Box<T>, T, impl for<'r> Fn(&'r mut Box<T>)>
pub fn for_box_mut<T>() -> WritableKeyPath<Box<T>, T, impl for<'r> Fn(&'r mut Box<T>)>
Unwrap Box