Trait partial_ref::PartialRef
source · pub trait PartialRef<'a>: Sized {
type Target: PartialRefTarget + ?Sized;
unsafe fn from_raw(
ptr: *mut <Self::Target as PartialRefTarget>::RawTarget
) -> Self;
fn get_raw(&self) -> *mut <Self::Target as PartialRefTarget>::RawTarget;
fn borrow<'b, BorrowedRef, SubsetIndex>(&'b mut self) -> BorrowedRef
where
'a: 'b,
BorrowedRef: PartialRef<'a, Target = Self::Target>,
Self: HasSubset<'a, BorrowedRef, SubsetIndex>,
{ ... }
fn part<'b, FieldPart, PartIndex, FieldType>(
&'b mut self,
_part: FieldPart
) -> &'a FieldType
where
'a: 'b,
FieldType: ?Sized,
FieldPart: Part<PartType = Field<FieldType>>,
Self: PluckConst<'a, FieldPart, PartIndex>,
Self::Target: HasPart<FieldPart> + 'a,
{ ... }
fn part_mut<'b, FieldPart, PartIndex, FieldType>(
&'b mut self,
_part: FieldPart
) -> &'a mut FieldType
where
'a: 'b,
FieldType: ?Sized,
FieldPart: Part<PartType = Field<FieldType>>,
Self: PluckMut<'a, FieldPart, PartIndex>,
Self::Target: HasPart<FieldPart> + 'a,
{ ... }
fn split_borrow<'b, BorrowedRef, SubsetIndex>(
&'b mut self
) -> (BorrowedRef, Self::Remainder)
where
'a: 'b,
BorrowedRef: PartialRef<'a, Target = Self::Target>,
Self: HasSubset<'a, BorrowedRef, SubsetIndex>,
{ ... }
fn split_part<'b, FieldPart, PartIndex, FieldType>(
&'b mut self,
_part: FieldPart
) -> (&'a FieldType, Self::Remainder)
where
'a: 'b,
FieldType: ?Sized,
FieldPart: Part<PartType = Field<FieldType>>,
Self: PluckConst<'a, FieldPart, PartIndex>,
Self::Target: HasPart<FieldPart> + 'a,
{ ... }
fn split_part_mut<'b, FieldPart, PartIndex, FieldType>(
&'b mut self,
_part: FieldPart
) -> (&'a mut FieldType, Self::Remainder)
where
'a: 'b,
FieldType: ?Sized,
FieldPart: Part<PartType = Field<FieldType>>,
Self: PluckMut<'a, FieldPart, PartIndex>,
Self::Target: HasPart<FieldPart> + 'a,
{ ... }
}
Expand description
Required Associated Types
sourcetype Target: PartialRefTarget + ?Sized
type Target: PartialRefTarget + ?Sized
The referenced type.
Required Methods
sourceunsafe fn from_raw(
ptr: *mut <Self::Target as PartialRefTarget>::RawTarget
) -> Self
unsafe fn from_raw(
ptr: *mut <Self::Target as PartialRefTarget>::RawTarget
) -> Self
Create a partial reference from a raw pointer.
This is unsafe for two reasons. It can be used to dereference a raw pointer, which is already unsafe on its own, and it can be used to construct invalid partial references, for example containing the same mutable part twice. Thus extra care is required when calling this.
sourcefn get_raw(&self) -> *mut <Self::Target as PartialRefTarget>::RawTarget
fn get_raw(&self) -> *mut <Self::Target as PartialRefTarget>::RawTarget
Access to the underlying raw pointer.
Beware that this can be used even for an empty reference with no parts. Doing anything with the resulting pointer is very likely unsafe, even if the partial reference is still in scope.
Provided Methods
sourcefn borrow<'b, BorrowedRef, SubsetIndex>(&'b mut self) -> BorrowedRefwhere
'a: 'b,
BorrowedRef: PartialRef<'a, Target = Self::Target>,
Self: HasSubset<'a, BorrowedRef, SubsetIndex>,
fn borrow<'b, BorrowedRef, SubsetIndex>(&'b mut self) -> BorrowedRefwhere
'a: 'b,
BorrowedRef: PartialRef<'a, Target = Self::Target>,
Self: HasSubset<'a, BorrowedRef, SubsetIndex>,
Partially re-borrows a partial reference.
This returns a new partial reference to the same value. The returned reference can have a subset of the original reference’s parts.
A typical use case is passing a reference to a function that requires fewer parts than the caller.
Usually the type parameters can be inferred.
sourcefn part<'b, FieldPart, PartIndex, FieldType>(
&'b mut self,
_part: FieldPart
) -> &'a FieldTypewhere
'a: 'b,
FieldType: ?Sized,
FieldPart: Part<PartType = Field<FieldType>>,
Self: PluckConst<'a, FieldPart, PartIndex>,
Self::Target: HasPart<FieldPart> + 'a,
fn part<'b, FieldPart, PartIndex, FieldType>(
&'b mut self,
_part: FieldPart
) -> &'a FieldTypewhere
'a: 'b,
FieldType: ?Sized,
FieldPart: Part<PartType = Field<FieldType>>,
Self: PluckConst<'a, FieldPart, PartIndex>,
Self::Target: HasPart<FieldPart> + 'a,
Access a part of the referenced value.
This returns a plain reference to a single part.
The parameter is only present for type inference, its value is ignored. As all parts
implement Default
it is always possible to pass a default value, which is useful in
generic code.
Usually the type parameters can be inferred.
sourcefn part_mut<'b, FieldPart, PartIndex, FieldType>(
&'b mut self,
_part: FieldPart
) -> &'a mut FieldTypewhere
'a: 'b,
FieldType: ?Sized,
FieldPart: Part<PartType = Field<FieldType>>,
Self: PluckMut<'a, FieldPart, PartIndex>,
Self::Target: HasPart<FieldPart> + 'a,
fn part_mut<'b, FieldPart, PartIndex, FieldType>(
&'b mut self,
_part: FieldPart
) -> &'a mut FieldTypewhere
'a: 'b,
FieldType: ?Sized,
FieldPart: Part<PartType = Field<FieldType>>,
Self: PluckMut<'a, FieldPart, PartIndex>,
Self::Target: HasPart<FieldPart> + 'a,
Mutable access to a part of the referenced value.
This returns a plain mutable reference to a single part.
The parameter is only present for type inference, its value is ignored. As all parts
implement Default
it is always possible to pass a default value, which is useful in
generic code.
Usually the type parameters can be inferred.
sourcefn split_borrow<'b, BorrowedRef, SubsetIndex>(
&'b mut self
) -> (BorrowedRef, Self::Remainder)where
'a: 'b,
BorrowedRef: PartialRef<'a, Target = Self::Target>,
Self: HasSubset<'a, BorrowedRef, SubsetIndex>,
fn split_borrow<'b, BorrowedRef, SubsetIndex>(
&'b mut self
) -> (BorrowedRef, Self::Remainder)where
'a: 'b,
BorrowedRef: PartialRef<'a, Target = Self::Target>,
Self: HasSubset<'a, BorrowedRef, SubsetIndex>,
Partially re-borrows a partial reference, splitting off the remaining parts.
This is equivalent to borrow
but also returns a second partial
reference that contains all parts that can be used simultaneously with the re-borrowed
reference.
This means that constant parts are contained in both references, while mutable parts that are re-borrowed are missing from the second partial reference. Mutable parts that are re-borrowed as constant parts are constant parts of both references.
Usually the type parameters can be inferred.
sourcefn split_part<'b, FieldPart, PartIndex, FieldType>(
&'b mut self,
_part: FieldPart
) -> (&'a FieldType, Self::Remainder)where
'a: 'b,
FieldType: ?Sized,
FieldPart: Part<PartType = Field<FieldType>>,
Self: PluckConst<'a, FieldPart, PartIndex>,
Self::Target: HasPart<FieldPart> + 'a,
fn split_part<'b, FieldPart, PartIndex, FieldType>(
&'b mut self,
_part: FieldPart
) -> (&'a FieldType, Self::Remainder)where
'a: 'b,
FieldType: ?Sized,
FieldPart: Part<PartType = Field<FieldType>>,
Self: PluckConst<'a, FieldPart, PartIndex>,
Self::Target: HasPart<FieldPart> + 'a,
Access a part of the referenced value, splitting off the remaining parts.
This is equivalent to part
but also returns a partial reference as
described in split_borrow
.
sourcefn split_part_mut<'b, FieldPart, PartIndex, FieldType>(
&'b mut self,
_part: FieldPart
) -> (&'a mut FieldType, Self::Remainder)where
'a: 'b,
FieldType: ?Sized,
FieldPart: Part<PartType = Field<FieldType>>,
Self: PluckMut<'a, FieldPart, PartIndex>,
Self::Target: HasPart<FieldPart> + 'a,
fn split_part_mut<'b, FieldPart, PartIndex, FieldType>(
&'b mut self,
_part: FieldPart
) -> (&'a mut FieldType, Self::Remainder)where
'a: 'b,
FieldType: ?Sized,
FieldPart: Part<PartType = Field<FieldType>>,
Self: PluckMut<'a, FieldPart, PartIndex>,
Self::Target: HasPart<FieldPart> + 'a,
Mutable access to a part of the referenced value, splitting off the remaining parts.
This is equivalent to part_mut
but also returns a partial
reference as described in split_borrow
.
Implementors
sourceimpl<'a, SomePart: Part, Reference: PartialRef<'a>> PartialRef<'a> for Const<SomePart, Reference>where
Reference::Target: HasPart<SomePart>,
impl<'a, SomePart: Part, Reference: PartialRef<'a>> PartialRef<'a> for Const<SomePart, Reference>where
Reference::Target: HasPart<SomePart>,
Extending a valid reference by a constant part is still a valid reference when the reference target has such a part.
type Target = <Reference as PartialRef<'a>>::Target
sourceimpl<'a, SomePart: Part, Reference: PartialRef<'a>> PartialRef<'a> for Mut<SomePart, Reference>where
Reference::Target: HasPart<SomePart>,
impl<'a, SomePart: Part, Reference: PartialRef<'a>> PartialRef<'a> for Mut<SomePart, Reference>where
Reference::Target: HasPart<SomePart>,
Extending a valid reference by a mutable part is still a valid reference when the reference target has such a part.
type Target = <Reference as PartialRef<'a>>::Target
sourceimpl<'a, Target: PartialRefTarget + ?Sized> PartialRef<'a> for Ref<'a, Target>
impl<'a, Target: PartialRefTarget + ?Sized> PartialRef<'a> for Ref<'a, Target>
An empty reference to a valid target is a valid reference.