AnyKeyPath

Struct AnyKeyPath 

Source
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 Root and Value types are completely erased
  • We store TypeId instead 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

Source

pub fn new<Root, Value>( keypath: OptionalKeyPath<Root, Value, impl for<'r> Fn(&'r Root) -> Option<&'r Value> + 'static>, ) -> Self
where Root: Any + 'static, Value: Any + 'static,

Source

pub fn from<Root, Value>( keypath: OptionalKeyPath<Root, Value, impl for<'r> Fn(&'r Root) -> Option<&'r Value> + 'static>, ) -> Self
where Root: Any + 'static, Value: Any + 'static,

Create an AnyKeyPath from a concrete OptionalKeyPath Alias for new() for consistency with from() pattern

Source

pub fn get<'r>(&self, root: &'r dyn Any) -> Option<&'r dyn Any>

Source

pub fn root_type_id(&self) -> TypeId

Get the TypeId of the Root type

Source

pub fn value_type_id(&self) -> TypeId

Get the TypeId of the Value type

Source

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

Source

pub fn kind_name(&self) -> String

Get a human-readable name for the value type Returns a string representation of the TypeId

Source

pub fn for_arc<Root>(&self) -> AnyKeyPath
where Root: Any + 'static,

Adapt this keypath to work with Arc instead of Root

Source

pub fn for_box<Root>(&self) -> AnyKeyPath
where Root: Any + 'static,

Adapt this keypath to work with Box instead of Root

Source

pub fn for_rc<Root>(&self) -> AnyKeyPath
where Root: Any + 'static,

Adapt this keypath to work with Rc instead of Root

Source

pub fn for_option<Root>(&self) -> AnyKeyPath
where Root: Any + 'static,

Adapt this keypath to work with Option instead of Root

Source

pub fn for_result<Root, E>(&self) -> AnyKeyPath
where Root: Any + 'static, E: Any + 'static,

Adapt this keypath to work with Result<Root, E> instead of Root

Source

pub fn for_arc_rwlock<Root>(&self) -> AnyKeyPath
where Root: Any + Clone + 'static,

Adapt this keypath to work with Arc<RwLock> instead of Root Note: This requires the Root to be cloned first, then use the keypath on the cloned value

Source

pub fn for_arc_mutex<Root>(&self) -> AnyKeyPath
where Root: Any + Clone + 'static,

Adapt this keypath to work with Arc<Mutex> instead of Root Note: This requires the Root to be cloned first, then use the keypath on the cloned value

Trait Implementations§

Source§

impl Clone for AnyKeyPath

Source§

fn clone(&self) -> AnyKeyPath

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.