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

A partial reference.

This is implemented by variants of Ref, Mut and Const. This is only implemented if the parts of any contained Mut or Const are valid for the referenced type.

Required Associated Types

The referenced type.

Required Methods

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.

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

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.

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.

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.

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.

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.

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

Extending a valid reference by a constant part is still a valid reference when the reference target has such a part.

Extending a valid reference by a mutable part is still a valid reference when the reference target has such a part.

An empty reference to a valid target is a valid reference.