pub struct Transparent<T> { /* private fields */ }Expand description
A type that transparently implements PartialEq and Hash, to be used
in structs that carry additional data that should not be relevant in comparisons.
It additionally supports creating dummy values and they will also compare equal to all other and hash identically.
The use of a Transparent<_> as a field of a struct should be understood
to convey the following intent: this field is useful only for diagnostics
and is never relevant for decisions.
This makes Transparent::forge suitable for use in unit tests where said
diagnostic data may not be available and we still want the computation to
be unaffected.
In fact the computation is guaranteed to be unaffected because Transparent
provides no peeking method, and the only way to extract data is unwrap
that will panic if the inner value was forged.
Implementations§
Source§impl<T> Transparent<T>
impl<T> Transparent<T>
Sourcepub fn unwrap(self) -> T
pub fn unwrap(self) -> T
Assert that the value was not forged and get its contents.
§Panics
fails if self was obtainedy by Transparent::forge().
Sourcepub fn forge(loc: &'static str) -> Self
pub fn forge(loc: &'static str) -> Self
Create a dummy value.
It is recommended to use the loc parameter as a way to track the location
where it was forged so that if it is accidentally unwrapped the error message
is more readable, e.g. by using either an identifying string or even better
the output of the here!() macro that gives the location in the source code.
Source§impl<T> Transparent<Option<T>>
impl<T> Transparent<Option<T>>
Sourcepub fn try_override_inner(&mut self, t: T)
pub fn try_override_inner(&mut self, t: T)
If there is not already data, add it. This is a noop if the contents were not forged.
Source§impl<T> Transparent<Transparent<T>>
impl<T> Transparent<Transparent<T>>
Sourcepub fn flatten(self) -> Transparent<T>
pub fn flatten(self) -> Transparent<T>
Remove the outer Transparent
Source§impl<T> Transparent<Option<T>>
impl<T> Transparent<Option<T>>
Sourcepub fn flatten(self) -> Option<Transparent<T>>
pub fn flatten(self) -> Option<Transparent<T>>
Remove the outer Transparent
Source§impl<T> Transparent<T>
impl<T> Transparent<T>
Trait Implementations§
Source§impl<T: Clone> Clone for Transparent<T>
impl<T: Clone> Clone for Transparent<T>
Source§fn clone(&self) -> Transparent<T>
fn clone(&self) -> Transparent<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more