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>,
) -> PartialKeyPath<Root>where
Value: Any + 'static,
Root: 'static,
Sourcepub fn from<Value>(
keypath: KeyPath<Root, Value, impl for<'r> Fn(&'r Root) -> &'r Value + 'static>,
) -> PartialKeyPath<Root>where
Value: Any + 'static,
Root: 'static,
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
pub fn get<'r>(&self, root: &'r Root) -> &'r (dyn Any + 'static)
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>(&self, root: &'a Root) -> Option<&'a Value>where
Value: Any,
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
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 for PartialKeyPath<Root>where
Root: Clone,
impl<Root> Clone for PartialKeyPath<Root>where
Root: Clone,
Source§fn clone(&self) -> PartialKeyPath<Root>
fn clone(&self) -> PartialKeyPath<Root>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more