PartialKeyPath

Struct PartialKeyPath 

Source
pub struct PartialKeyPath<Root> { /* private fields */ }
Expand description

PartialKeyPath - Hides the Value type but keeps Root visible Useful for storing keypaths in collections without knowing the exact Value type

§Why PhantomData?

PhantomData<Root> is needed because:

  1. The Root type parameter is not actually stored in the struct (only used in the closure)
  2. Rust needs to know the generic type parameter for:
    • Type checking at compile time
    • Ensuring correct usage (e.g., PartialKeyPath<User> can only be used with &User)
    • Preventing mixing different Root types
  3. Without PhantomData, Rust would complain that Root is unused
  4. PhantomData is zero-sized - it adds no runtime overhead

Implementations§

Source§

impl<Root> PartialKeyPath<Root>

Source

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

Source

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

Create a PartialKeyPath from a concrete KeyPath Alias for new() for consistency with from() pattern

Source

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

Source

pub fn value_type_id(&self) -> TypeId

Get the TypeId of the Value type

Source

pub fn get_as<'a, Value>(&self, root: &'a Root) -> Option<&'a Value>
where Value: Any,

Try to downcast the result to a specific type

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(&self) -> PartialOptionalKeyPath<Arc<Root>>
where Root: 'static,

Adapt this keypath to work with Arc instead of Root

Source

pub fn for_box(&self) -> PartialOptionalKeyPath<Box<Root>>
where Root: 'static,

Adapt this keypath to work with Box instead of Root

Source

pub fn for_rc(&self) -> PartialOptionalKeyPath<Rc<Root>>
where Root: 'static,

Adapt this keypath to work with Rc instead of Root

Source

pub fn for_option(&self) -> PartialOptionalKeyPath<Option<Root>>
where Root: 'static,

Adapt this keypath to work with Option instead of Root

Source

pub fn for_result<E>(&self) -> PartialOptionalKeyPath<Result<Root, E>>
where Root: 'static, E: 'static,

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

Source

pub fn for_arc_rwlock(&self) -> PartialOptionalKeyPath<Arc<RwLock<Root>>>
where Root: 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 Example: keypath.get_as::<Value>(&arc_rwlock.read().unwrap().clone())

Source

pub fn for_arc_mutex(&self) -> PartialOptionalKeyPath<Arc<Mutex<Root>>>
where Root: 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 Example: keypath.get_as::<Value>(&arc_mutex.lock().unwrap().clone())

Trait Implementations§

Source§

impl<Root> Clone for PartialKeyPath<Root>
where Root: Clone,

Source§

fn clone(&self) -> PartialKeyPath<Root>

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
Source§

impl<Root> From<PartialKeyPath<Root>> for PKP<Root>

Source§

fn from(kp: RustPartialKeyPath<Root>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<Root> Freeze for PartialKeyPath<Root>

§

impl<Root> !RefUnwindSafe for PartialKeyPath<Root>

§

impl<Root> !Send for PartialKeyPath<Root>

§

impl<Root> !Sync for PartialKeyPath<Root>

§

impl<Root> Unpin for PartialKeyPath<Root>
where Root: Unpin,

§

impl<Root> !UnwindSafe for PartialKeyPath<Root>

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.