pub struct Pass(/* private fields */);Expand description
A key for reading/writing to RwData
This key is necessary in order to prevent breakage of the number one rule of Rust: any number of shared references, or one exclusive reference.
When you call RwData::read, any call to RwData::write may
end up breaking this rule, and vice-versa, which is why this
struct is necessary.
One downside of this approach is that it is even more restrictive
than Rust’s rule of thumb, since that one is enforced on
individual instances, while this one is enforced on all
RwDatas. This (as far as i know) cannot be circumvented, as a
more advanced compile time checker (that distinguishes
RwData<T>s of different Ts, for example) does not seem
feasible without the use of unfinished features, which I am not
willing to use.
Implementations§
Source§impl Pass
impl Pass
Sourcepub fn write_two<'a, L: 'static, R: 'static>(
&'a mut self,
lhs: &'a RwData<L>,
rhs: &'a RwData<R>,
) -> (&'a mut L, &'a mut R)
pub fn write_two<'a, L: 'static, R: 'static>( &'a mut self, lhs: &'a RwData<L>, rhs: &'a RwData<R>, ) -> (&'a mut L, &'a mut R)
Writes to two RwData at the same time
This can only be done when the RwDatas are of different
types since, if they were of the same type, they could be
pointing to the same data, which would be undefined behaviour.
Also, this may only be done with sized types, since for
example, an RwData<Buffer> could point to the same
Buffer as some RwData<dyn Widget>, even if dyn Widget and Buffer are “different types.
§Panics
For now, due to the inability to compary two TypeIds at
compile time in stable Rust, calling this function on two
RwDatas of the same type will simply panic at runtime.
However, in the future, once PartialEq is allowed in const
contexts, this function will refuse to compile if the
RwDatas are of the same type.
In practice, the outcome ends up being the same, since breaking that invariant results in the rejection of your conde regardless, it will just happen in a more convenient place in the future.
Sourcepub fn read_and_write<'a, L: 'static, R: 'static>(
&'a mut self,
lhs: &'a RwData<L>,
rhs: &'a RwData<R>,
) -> (&'a L, &'a mut R)
pub fn read_and_write<'a, L: 'static, R: 'static>( &'a mut self, lhs: &'a RwData<L>, rhs: &'a RwData<R>, ) -> (&'a L, &'a mut R)
Writes to one RwData and reads from another at the same
time
This can only be done when the RwDatas are of different
types since, if they were of the same type, they could be
pointing to the same data, which would be undefined behaviour.
Also, this may only be done with sized types, since for
example, an RwData<Buffer> could point to the same
Buffer as some RwData<dyn Widget>, even if dyn Widget and Buffer are “different types.
§Panics
For now, due to the inability to compary two TypeIds at
compile time in stable Rust, calling this function on two
RwDatas of the same type will simply panic at runtime.
However, in the future, once PartialEq is allowed in const
contexts, this function will refuse to compile if the
RwDatas are of the same type.
In practice, the outcome ends up being the same, since breaking that invariant results in the rejection of your conde regardless, it will just happen in a more convenient place in the future.
Sourcepub fn try_write_two<'a, L: ?Sized + 'static, R: ?Sized + 'static>(
&'a mut self,
lhs: &'a RwData<L>,
rhs: &'a RwData<R>,
) -> Option<(&'a mut L, &'a mut R)>
pub fn try_write_two<'a, L: ?Sized + 'static, R: ?Sized + 'static>( &'a mut self, lhs: &'a RwData<L>, rhs: &'a RwData<R>, ) -> Option<(&'a mut L, &'a mut R)>
Tries to write to two RwData at the same time, failing if
they point to the same data
Almost all the time, you will want to use Pass::write_two
instead of this function, since it always returns and is
checked at compile time. There are only two situations
where you should consider using this function:
- One or two of the
RwDatas point to unsized types. - They point to the same type.
Given these two constraints however, you should still make
sure that the two RwDatas don’t point to the same data.
Sourcepub fn try_read_and_write<'a, L: ?Sized + 'static, R: ?Sized + 'static>(
&'a mut self,
lhs: &'a RwData<L>,
rhs: &'a RwData<R>,
) -> Option<(&'a L, &'a mut R)>
pub fn try_read_and_write<'a, L: ?Sized + 'static, R: ?Sized + 'static>( &'a mut self, lhs: &'a RwData<L>, rhs: &'a RwData<R>, ) -> Option<(&'a L, &'a mut R)>
Tries to write to one RwData and reads from another at the
same time
Almost all the time, you will want to use
Pass::read_and_write instead of this function, since
it always returns and is checked at compile time. There
are only two situations where you should consider using
this function:
- One or two of the
RwDatas point to unsized types. - They point to the same type.
Given these two constraints however, you should still make
sure that the two RwDatas don’t point to the same data.
Auto Trait Implementations§
impl Freeze for Pass
impl RefUnwindSafe for Pass
impl Send for Pass
impl Sync for Pass
impl Unpin for Pass
impl UnwindSafe for Pass
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.