#[non_exhaustive]pub enum Unknown<T> {
Discarded(PhantomData<T>),
Retained(T),
}Expand description
Information about unknown values, which may have been retained as a T
Won’t grow additional variants - but, Retained is only included conditionally.
Also used in the form Unknown<()> to indicate whether unknown values should be retained.
§Example
#![cfg(feature = "retain-unknown")]
use tor_netdoc::types::Unknown;
let mut unk: Unknown<Vec<String>> = Unknown::new_retained_default();
unk.with_mut_unknown(|u| u.push("something-we-found".into()));
assert_eq!(unk.into_retained().unwrap(), ["something-we-found"]);§Equality comparison, semantics
Two Unknown are consider equal if both have the same record of unknown values,
or if neither records unknown values at all.
Unknown is not Eq or Ord because we won’t want to relate a Discarded
to a Retained. That would be a a logic error. partial_cmp gives None for this.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Discarded(PhantomData<T>)
The parsing discarded unknown values and they are no longer available.
Retained(T)
retain-unknown only.The document parsing retained (or should retain) unknown values.
Implementations§
Source§impl<T> Unknown<T>
impl<T> Unknown<T>
Sourcepub fn new_discard() -> Self
pub fn new_discard() -> Self
Create an Unknown which specifies that values were discarded (or should be)
Sourcepub fn try_map<U, E>(
self,
f: impl FnOnce(T) -> Result<U, E>,
) -> Result<Unknown<U>, E>
pub fn try_map<U, E>( self, f: impl FnOnce(T) -> Result<U, E>, ) -> Result<Unknown<U>, E>
Map the Retained, fallibly
Sourcepub fn into_retained(self) -> Result<T, Bug>
Available on crate feature retain-unknown only.
pub fn into_retained(self) -> Result<T, Bug>
retain-unknown only.Obtain the Retained data
Treats lack of retention as an internal error.
Sourcepub fn new_retained_default() -> Selfwhere
T: Default,
Available on crate feature retain-unknown only.
pub fn new_retained_default() -> Selfwhere
T: Default,
retain-unknown only.Start recording unknown information, with a default value for T
Sourcepub fn with_mut_unknown(&mut self, f: impl FnOnce(&mut T))
pub fn with_mut_unknown(&mut self, f: impl FnOnce(&mut T))
Update the Retained, if there is one
Intended for use in parsing, when we encounter an unknown value.
Not provided in try_ form. If you think you need this, instead, unconditionally
parse and verify the unknown value, and then conditionally insert it with this function.
Don’t parse it conditionally - that would skip some validation.
Trait Implementations§
Source§impl<T: PartialOrd> PartialOrd for Unknown<T>
impl<T: PartialOrd> PartialOrd for Unknown<T>
impl<T: Copy> Copy for Unknown<T>
impl<T> StructuralPartialEq for Unknown<T>
Auto Trait Implementations§
impl<T> Freeze for Unknown<T>where
T: Freeze,
impl<T> RefUnwindSafe for Unknown<T>where
T: RefUnwindSafe,
impl<T> Send for Unknown<T>where
T: Send,
impl<T> Sync for Unknown<T>where
T: Sync,
impl<T> Unpin for Unknown<T>where
T: Unpin,
impl<T> UnwindSafe for Unknown<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>, which can then be
downcast into Box<dyn 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>, which 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.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more