pub struct AnyKeyPath { /* private fields */ }Expand description
AnyKeyPath - Hides both Root and Value types Equivalent to Swift’s AnyKeyPath Useful for storing keypaths in collections without knowing either type
§Why No PhantomData?
Unlike PartialKeyPath, AnyKeyPath doesn’t need PhantomData because:
- Both
RootandValuetypes are completely erased - We store
TypeIdinstead for runtime type checking - The type information is encoded in the closure’s behavior, not the struct
- There’s no generic type parameter to track at compile time
Implementations§
Source§impl AnyKeyPath
impl AnyKeyPath
pub fn new<Root, Value>( keypath: OptionalKeyPath<Root, Value, impl for<'r> Fn(&'r Root) -> Option<&'r Value> + 'static>, ) -> Self
Sourcepub fn from<Root, Value>(
keypath: OptionalKeyPath<Root, Value, impl for<'r> Fn(&'r Root) -> Option<&'r Value> + 'static>,
) -> Self
pub fn from<Root, Value>( keypath: OptionalKeyPath<Root, Value, impl for<'r> Fn(&'r Root) -> Option<&'r Value> + 'static>, ) -> Self
Create an AnyKeyPath from a concrete OptionalKeyPath
Alias for new() for consistency with from() pattern
pub fn get<'r>(&self, root: &'r dyn Any) -> Option<&'r dyn Any>
Sourcepub fn root_type_id(&self) -> TypeId
pub fn root_type_id(&self) -> TypeId
Get the TypeId of the Root type
Sourcepub fn value_type_id(&self) -> TypeId
pub fn value_type_id(&self) -> TypeId
Get the TypeId of the Value type
Sourcepub fn get_as<'a, Root: Any, Value: Any>(
&self,
root: &'a Root,
) -> Option<Option<&'a Value>>
pub fn get_as<'a, Root: Any, Value: Any>( &self, root: &'a Root, ) -> Option<Option<&'a Value>>
Try to get the value with type checking
Sourcepub fn kind_name(&self) -> String
pub fn kind_name(&self) -> String
Get a human-readable name for the value type Returns a string representation of the TypeId
Sourcepub fn for_arc<Root>(&self) -> AnyKeyPathwhere
Root: Any + 'static,
pub fn for_arc<Root>(&self) -> AnyKeyPathwhere
Root: Any + 'static,
Adapt this keypath to work with Arc
Sourcepub fn for_box<Root>(&self) -> AnyKeyPathwhere
Root: Any + 'static,
pub fn for_box<Root>(&self) -> AnyKeyPathwhere
Root: Any + 'static,
Adapt this keypath to work with Box
Sourcepub fn for_rc<Root>(&self) -> AnyKeyPathwhere
Root: Any + 'static,
pub fn for_rc<Root>(&self) -> AnyKeyPathwhere
Root: Any + 'static,
Adapt this keypath to work with Rc
Sourcepub fn for_option<Root>(&self) -> AnyKeyPathwhere
Root: Any + 'static,
pub fn for_option<Root>(&self) -> AnyKeyPathwhere
Root: Any + 'static,
Adapt this keypath to work with Option
Sourcepub fn for_result<Root, E>(&self) -> AnyKeyPath
pub fn for_result<Root, E>(&self) -> AnyKeyPath
Adapt this keypath to work with Result<Root, E> instead of Root
Sourcepub fn for_arc_rwlock<Root>(&self) -> AnyKeyPath
pub fn for_arc_rwlock<Root>(&self) -> AnyKeyPath
Adapt this keypath to work with Arc<RwLock
Sourcepub fn for_arc_mutex<Root>(&self) -> AnyKeyPath
pub fn for_arc_mutex<Root>(&self) -> AnyKeyPath
Adapt this keypath to work with Arc<Mutex
Trait Implementations§
Source§impl Clone for AnyKeyPath
impl Clone for AnyKeyPath
Source§fn clone(&self) -> AnyKeyPath
fn clone(&self) -> AnyKeyPath
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for AnyKeyPath
impl !RefUnwindSafe for AnyKeyPath
impl !Send for AnyKeyPath
impl !Sync for AnyKeyPath
impl Unpin for AnyKeyPath
impl !UnwindSafe for AnyKeyPath
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)