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
Sourcepub fn get_as<'a, Value: Any>(&self, root: &'a Root) -> Option<&'a Value>
pub fn get_as<'a, Value: Any>(&self, root: &'a Root) -> Option<&'a Value>
Try to downcast the result to a specific type
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(&self) -> PartialOptionalKeyPath<Arc<Root>>where
Root: 'static,
pub fn for_arc(&self) -> PartialOptionalKeyPath<Arc<Root>>where
Root: 'static,
Adapt this keypath to work with Arc
Sourcepub fn for_box(&self) -> PartialOptionalKeyPath<Box<Root>>where
Root: 'static,
pub fn for_box(&self) -> PartialOptionalKeyPath<Box<Root>>where
Root: 'static,
Adapt this keypath to work with Box
Sourcepub fn for_rc(&self) -> PartialOptionalKeyPath<Rc<Root>>where
Root: 'static,
pub fn for_rc(&self) -> PartialOptionalKeyPath<Rc<Root>>where
Root: 'static,
Adapt this keypath to work with Rc
Sourcepub fn for_option(&self) -> PartialOptionalKeyPath<Option<Root>>where
Root: 'static,
pub fn for_option(&self) -> PartialOptionalKeyPath<Option<Root>>where
Root: 'static,
Adapt this keypath to work with Option
Sourcepub fn for_result<E>(&self) -> PartialOptionalKeyPath<Result<Root, E>>where
Root: 'static,
E: 'static,
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
Sourcepub fn for_arc_rwlock(&self) -> PartialOptionalKeyPath<Arc<RwLock<Root>>>where
Root: Clone + 'static,
pub fn for_arc_rwlock(&self) -> PartialOptionalKeyPath<Arc<RwLock<Root>>>where
Root: Clone + 'static,
Adapt this keypath to work with Arc<RwLockkeypath.get_as::<Value>(&arc_rwlock.read().unwrap().clone())
Sourcepub fn for_arc_mutex(&self) -> PartialOptionalKeyPath<Arc<Mutex<Root>>>where
Root: Clone + 'static,
pub fn for_arc_mutex(&self) -> PartialOptionalKeyPath<Arc<Mutex<Root>>>where
Root: Clone + 'static,
Adapt this keypath to work with Arc<Mutexkeypath.get_as::<Value>(&arc_mutex.lock().unwrap().clone())
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>
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
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§
§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)