pub struct PotentialMutableBorrow<T: ?Sized>(/* private fields */);
Expand description
A variant of MutableBorrow
which represents a mutable borrow which can gracefully recover from
borrow errors if they end up occurring.
Unlike a MutableBorrow
, this token will not trigger a warning if a confounding borrow is
potentially alive at the same time as it since, if the dynamic borrow this borrow guard backs
ends up aliasing with something else, the error is assumed to be handled gracefully.
As with borrow_mutably
and friends, setting T
to Nothing
causes this guard to have no
effect on the statically-analyzed borrow counts.
If the error cannot be handled gracefully, one may construct a MutableBorrow
and
downgrade
it to a PotentialMutableBorrow
so that the static
analyzer will start reporting these potentially aliasing borrows again.
See the Potential Borrows section of the crate documentation for more details.
Implementations§
Source§impl<T: ?Sized> PotentialMutableBorrow<T>
impl<T: ?Sized> PotentialMutableBorrow<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Constructs a new PotentialMutableBorrow
guard.
This function has no runtime cost but will cause the AuToken static analyzer to increment the
number of mutable borrows of type T
in scope. Note, however, that it will not cause the
static analyzer to report aliases with potentially confounding borrow tokens. See the structure
documentation for details.
Internally, this function calls:
autoken::assume_no_alias(|| MutableBorrow::<T>::new());
Sourcepub fn loan(&mut self) -> MutableBorrow<Nothing<'_>>
pub fn loan(&mut self) -> MutableBorrow<Nothing<'_>>
Creates a loaned MutableBorrow
of this guard which has no effect on the static analysis
borrow counters by itself, making it safe to use in conditional code.
This is typically used to construct the MutableBorrow
guard for runtime borrow guards which
were successfully created in fallible code.
See the Making Sense of Control Flow Errors section of the crate documentation for more details on loans.
Sourcepub fn assume_no_alias_loan(&self) -> MutableBorrow<Nothing<'_>>
pub fn assume_no_alias_loan(&self) -> MutableBorrow<Nothing<'_>>
Creates a loaned MutableBorrow
of this guard which has no effect on the static analysis
borrow counters by itself, making it safe to use in conditional code.
This is typically used to construct the MutableBorrow
guard for runtime borrow guards which
were successfully created in fallible code.
Unlike loan, this method takes an immutable reference to the
loaning PotentialMutableBorrow
, which makes it more prone to accidental borrow aliasing.
See the Making Sense of Control Flow Errors section of the crate documentation for more details on loans.
Sourcepub fn strip_lifetime_analysis(self) -> PotentialMutableBorrow<Nothing<'static>>
pub fn strip_lifetime_analysis(self) -> PotentialMutableBorrow<Nothing<'static>>
Transforms the type of T
into Nothing
, effectively making it as if this borrow guard no
longer exists.
See the Making Sense of Control Flow Errors
section of the crate documentation for more details on the utility of strip_lifetime_analysis
.