pub struct QCellOwner { /* private fields */ }Expand description
Borrowing-owner of zero or more QCell instances.
The owner will have a temporally unique ID associated with it to
detect use of the wrong owner to access a cell at runtime, which
is a programming error. Temporally unique means that at any one
time, only one owner will hold that ID. This type derives the
owner ID from the address of an internal memory allocation which
this owner holds until it is dropped, which ensures that the ID is
temporally unique. The allocation is aligned to ensure that its
ID cannot collide with those created using QCellOwnerSeq.
In a no_std environment this requires the alloc feature
because it allocates memory. For a no_std environment without
alloc, consider using QCellOwnerSeq or QCellOwnerPinned.
§Safety
This should successfully defend against all malicious and unsafe use. If not, please raise an issue. The same unique ID may later be allocated to someone else once you drop the returned owner, but this cannot be abused to cause unsafe access to cells because there will still be only one owner active at any one time with that ID. Also it cannot be used maliciously to access cells which don’t belong to the new caller, because you also need a reference to the cells. So for example if you have a graph of cells that is only accessible through a private structure, then if someone else gets the same owner ID later, it makes no difference, because they have no way to get a reference to those cells. In any case, you are probably going to drop all those cells at the same time as dropping the owner, because they are no longer of any use without the owner ID.
See crate documentation.
Implementations§
Source§impl QCellOwner
impl QCellOwner
Sourcepub fn new() -> Self
Available on crate feature alloc only.
pub fn new() -> Self
alloc only.Create an owner that can be used for creating many QCell
instances.
Sourcepub fn id(&self) -> QCellOwnerID
Available on crate feature alloc only.
pub fn id(&self) -> QCellOwnerID
alloc only.Get the internal owner ID. This may be used to create QCell
instances without needing a borrow on this structure, which is
useful if this structure is already borrowed.
Sourcepub fn cell<T>(&self, value: T) -> QCell<T>
Available on crate feature alloc only.
pub fn cell<T>(&self, value: T) -> QCell<T>
alloc only.Create a new cell owned by this owner instance. See also
QCell::new.
Sourcepub fn ro<'a, T: ?Sized>(&'a self, qc: &'a QCell<T>) -> &'a T
Available on crate feature alloc only.
pub fn ro<'a, T: ?Sized>(&'a self, qc: &'a QCell<T>) -> &'a T
alloc only.Borrow contents of a QCell immutably (read-only). Many
QCell instances can be borrowed immutably at the same time
from the same owner. Panics if the QCell is not owned by
this QCellOwner.
Sourcepub fn rw<'a, T: ?Sized>(&'a mut self, qc: &'a QCell<T>) -> &'a mut T
Available on crate feature alloc only.
pub fn rw<'a, T: ?Sized>(&'a mut self, qc: &'a QCell<T>) -> &'a mut T
alloc only.Borrow contents of a QCell mutably (read-write). Only one
QCell at a time can be borrowed from the owner using this
call. The returned reference must go out of scope before
another can be borrowed. Panics if the QCell is not owned
by this QCellOwner.
Sourcepub fn rw2<'a, T: ?Sized, U: ?Sized>(
&'a mut self,
qc1: &'a QCell<T>,
qc2: &'a QCell<U>,
) -> (&'a mut T, &'a mut U)
Available on crate feature alloc only.
pub fn rw2<'a, T: ?Sized, U: ?Sized>( &'a mut self, qc1: &'a QCell<T>, qc2: &'a QCell<U>, ) -> (&'a mut T, &'a mut U)
alloc only.Borrow contents of two QCell instances mutably. Panics if
the two QCell instances point to the same memory. Panics
if either QCell is not owned by this QCellOwner.
Sourcepub fn rw3<'a, T: ?Sized, U: ?Sized, V: ?Sized>(
&'a mut self,
qc1: &'a QCell<T>,
qc2: &'a QCell<U>,
qc3: &'a QCell<V>,
) -> (&'a mut T, &'a mut U, &'a mut V)
Available on crate feature alloc only.
pub fn rw3<'a, T: ?Sized, U: ?Sized, V: ?Sized>( &'a mut self, qc1: &'a QCell<T>, qc2: &'a QCell<U>, qc3: &'a QCell<V>, ) -> (&'a mut T, &'a mut U, &'a mut V)
alloc only.Borrow contents of three QCell instances mutably. Panics
if any pair of QCell instances point to the same memory.
Panics if any QCell is not owned by this QCellOwner.
Trait Implementations§
Source§impl Default for QCellOwner
Available on crate feature alloc only.
impl Default for QCellOwner
alloc only.