pub struct TCellOwner<Q: 'static> { /* private fields */ }
Expand description
Borrowing-owner of zero or more TCell
instances.
See crate documentation.
Implementations§
Source§impl<Q: 'static> TCellOwner<Q>
impl<Q: 'static> TCellOwner<Q>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create the singleton owner instance. Each owner may be used
to create many TCell
instances. There may be only one
instance of this type per process at any given time for each
different marker type Q
. This call panics if a second
simultaneous instance is created.
Keep in mind that in Rust, tests are run in parallel unless
specified otherwise (using e.g. RUST_TEST_THREADS
), so
this panic may be more easy to trigger than you might think.
To avoid this panic, consider using the methods
TCellOwner::wait_for_new
or TCellOwner::try_new
instead.
Sourcepub fn try_new() -> Option<Self>
pub fn try_new() -> Option<Self>
Same as TCellOwner::new
, except if another TCellOwner
of this type Q
already exists, this returns None
instead
of panicking.
Sourcepub fn wait_for_new() -> Self
pub fn wait_for_new() -> Self
Same as TCellOwner::new
, except if another TCellOwner
of this type Q
already exists, this function blocks the thread
until that other instance is dropped. This will of course deadlock
if that other instance is owned by the same thread.
Note that owners are expected to be relatively long-lived. If
you need to access cells associated with a given marker type
from several different threads, the most efficient pattern is
to have a single long-lived owner shared between threads, with
a Mutex
or RwLock
to control access. This call is
intended to help when several independent tests need to run
which use the same marker type internally.
Sourcepub fn cell<T>(&self, value: T) -> TCell<Q, T>
pub fn cell<T>(&self, value: T) -> TCell<Q, T>
Create a new cell owned by this owner instance. See also
TCell::new
.
Sourcepub fn ro<'a, T: ?Sized>(&'a self, tc: &'a TCell<Q, T>) -> &'a T
pub fn ro<'a, T: ?Sized>(&'a self, tc: &'a TCell<Q, T>) -> &'a T
Borrow contents of a TCell
immutably (read-only). Many
TCell
instances can be borrowed immutably at the same time
from the same owner.
Sourcepub fn rw<'a, T: ?Sized>(&'a mut self, tc: &'a TCell<Q, T>) -> &'a mut T
pub fn rw<'a, T: ?Sized>(&'a mut self, tc: &'a TCell<Q, T>) -> &'a mut T
Borrow contents of a TCell
mutably (read-write). Only one
TCell
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.