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:
- The
Roottype parameter is not actually stored in the struct (only used in the closure) - 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
- Without
PhantomData, Rust would complain thatRootis unused PhantomDatais zero-sized - it adds no runtime overhead
Implementations§
Source§impl<Root> PartialKeyPath<Root>
impl<Root> PartialKeyPath<Root>
pub fn new<Value>(
keypath: KeyPath<Root, Value, impl for<'r> Fn(&'r Root) -> &'r Value + 'static>,
) -> Selfwhere
Value: Any + 'static,
Root: 'static,
Sourcepub fn from<Value>(
keypath: KeyPath<Root, Value, impl for<'r> Fn(&'r Root) -> &'r Value + 'static>,
) -> Selfwhere
Value: Any + 'static,
Root: 'static,
pub fn from<Value>(
keypath: KeyPath<Root, Value, impl for<'r> Fn(&'r Root) -> &'r Value + 'static>,
) -> Selfwhere
Value: Any + 'static,
Root: 'static,
Create a PartialKeyPath from a concrete KeyPath
Alias for new() for consistency with from() pattern
pub fn get<'r>(&self, root: &'r Root) -> &'r dyn Any
Sourcepub fn value_type_id(&self) -> TypeId
pub fn value_type_id(&self) -> TypeId
Get the TypeId of the Value type
Trait Implementations§
Source§impl<Root: Clone> Clone for PartialKeyPath<Root>
impl<Root: Clone> Clone for PartialKeyPath<Root>
Source§fn clone(&self) -> PartialKeyPath<Root>
fn clone(&self) -> PartialKeyPath<Root>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more