[−][src]Struct qcell::QCellOwner
Borrowing-owner of zero or more QCell
instances.
See crate documentation.
Methods
impl QCellOwner
[src]
pub fn new() -> Self
[src]
Create an owner that can be used for creating many QCell
instances. It will have a temporally unique ID associated
with it to detect using the wrong owner to access a cell at
runtime, which is a programming error. This is the slow and safe
version that uses a mutex and a free list to allocate IDs. If
speed of this call matters, then consider using
fast_new()
instead. This call will
panic if the limit of 2^31 owners active at the same time is
reached.
This safe version does successfully defend against all malicious and unsafe use, as far as I am aware. If not, please raise an issue. The same unique ID will 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 access to the cells. So for example if you have a graph of cells that is only accessible through a private structure, then someone else getting the same owner ID 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.
pub unsafe fn fast_new() -> Self
[src]
Create an owner that can be used for creating many QCell
instances. It will have a unique(-ish) ID associated with it
to detect using the wrong owner to access a cell at runtime,
which is a programming error. This call is much faster than
new()
because it uses a simple atomic
increment to get a new ID, but it could be used maliciously to
obtain unsafe behaviour, so the call is marked as unsafe
.
If used non-maliciously the chance of getting unsafe behaviour in practice is zero -- not just close to zero but actually zero. To get unsafe behaviour, you'd have to accidentally create exactly 2^31 more owners to get a duplicate ID and you'd also have to have a bug in your code where you try to use the wrong owner to access a cell (which should normally be rejected with a panic). Already this is vanishingly improbable, but then if that happened by accident on one run but not on another, your code would still panic and you would fix your bug. So once that bug in your code is fixed, the risk is zero. No amount of fuzz-testing could ever cause unsafe behaviour once that bug is fixed. So whilst strictly-speaking this call is unsafe, in practice there is no risk unless you really try hard to exploit it.
pub fn get<'a, T>(&'a self, qc: &'a QCell<T>) -> &'a T
[src]
Borrow contents of a QCell
immutably. 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
.
pub fn get_mut<'a, T>(&'a mut self, qc: &'a QCell<T>) -> &'a mut T
[src]
Borrow contents of a QCell
mutably. 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
.
pub fn get_mut2<'a, T, U>(
&'a mut self,
qc1: &'a QCell<T>,
qc2: &'a QCell<U>
) -> (&'a mut T, &'a mut U)
[src]
&'a mut self,
qc1: &'a QCell<T>,
qc2: &'a QCell<U>
) -> (&'a mut T, &'a mut U)
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
.
pub fn get_mut3<'a, T, U, V>(
&'a mut self,
qc1: &'a QCell<T>,
qc2: &'a QCell<U>,
qc3: &'a QCell<V>
) -> (&'a mut T, &'a mut U, &'a mut V)
[src]
&'a mut self,
qc1: &'a QCell<T>,
qc2: &'a QCell<U>,
qc3: &'a QCell<V>
) -> (&'a mut T, &'a mut U, &'a mut V)
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
impl Drop for QCellOwner
[src]
Auto Trait Implementations
impl Send for QCellOwner
impl Sync for QCellOwner
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,