pub struct ItemPresent<T: Default>(pub T);Expand description
An item that only matters in terms of presence of absence.
Useful for items such as tunnelled-dir-server where the mere presence
implies a truthful value.
This wrapper implements ItemValueParseable and ItemValueEncodable
rejecting all arguments and objects and just expecting/emitting the
keyword (or not).
§Examples
The following shows an except from a hypothetical netdoc with a
ItemPresent item.
use derive_deftly::Deftly;
use tor_netdoc::types::*;
use tor_netdoc::parse2::*;
use tor_netdoc::*;
#[derive(Debug, Default)]
struct Hello;
#[derive(Deftly, Debug)]
#[derive_deftly(NetdocParseable)]
struct TestDoc {
intro: Ignored,
hello: Option<ItemPresent<Hello>>,
}
// hello is not present.
let doc = parse_netdoc::<TestDoc>(&ParseInput::new("intro\n", "")).unwrap();
assert!(doc.hello.is_none());
// hello is present.
let doc = parse_netdoc::<TestDoc>(&ParseInput::new("intro\nhello\n", "")).unwrap();
assert!(doc.hello.is_some());
// hello has arguments which are ignored.
let doc = parse_netdoc::<TestDoc>(&ParseInput::new("intro\nhello world\n", "")).unwrap();
assert!(doc.hello.is_some());
// hello is present twice which is not allowed.
let doc = parse_netdoc::<TestDoc>(&ParseInput::new("intro\nhello\nhello\n", "")).unwrap_err();Tuple Fields§
§0: TTrait Implementations§
Source§impl<T: Default> AsMut<T> for ItemPresent<T>
impl<T: Default> AsMut<T> for ItemPresent<T>
Source§impl<T: Default> AsRef<T> for ItemPresent<T>
impl<T: Default> AsRef<T> for ItemPresent<T>
Source§impl<T: Clone + Default> Clone for ItemPresent<T>
impl<T: Clone + Default> Clone for ItemPresent<T>
Source§fn clone(&self) -> ItemPresent<T>
fn clone(&self) -> ItemPresent<T>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl<T: Copy + Default> Copy for ItemPresent<T>
Source§impl<T: Default + Default> Default for ItemPresent<T>
impl<T: Default + Default> Default for ItemPresent<T>
Source§fn default() -> ItemPresent<T>
fn default() -> ItemPresent<T>
Returns the “default value” for a type. Read more
Source§impl<T: Default> Deref for ItemPresent<T>
impl<T: Default> Deref for ItemPresent<T>
Source§impl<T: Default> DerefMut for ItemPresent<T>
impl<T: Default> DerefMut for ItemPresent<T>
impl<T: Eq + Default> Eq for ItemPresent<T>
Source§impl<T: Default> From<T> for ItemPresent<T>
impl<T: Default> From<T> for ItemPresent<T>
Source§impl<T: Default> ItemValueEncodable for ItemPresent<T>
impl<T: Default> ItemValueEncodable for ItemPresent<T>
Source§fn write_item_value_onto(&self, out: ItemEncoder<'_>) -> StdResult<(), Bug>
fn write_item_value_onto(&self, out: ItemEncoder<'_>) -> StdResult<(), Bug>
Write the item’s arguments, and any object, onto
out Read moreSource§impl<T: Default> ItemValueParseable for ItemPresent<T>
impl<T: Default> ItemValueParseable for ItemPresent<T>
Source§fn from_unparsed(item: UnparsedItem<'_>) -> StdResult<Self, EP>
fn from_unparsed(item: UnparsedItem<'_>) -> StdResult<Self, EP>
Parse the item’s value
Source§impl<T: Ord + Default> Ord for ItemPresent<T>
impl<T: Ord + Default> Ord for ItemPresent<T>
Source§fn cmp(&self, other: &ItemPresent<T>) -> Ordering
fn cmp(&self, other: &ItemPresent<T>) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<T: PartialEq + Default> PartialEq for ItemPresent<T>
impl<T: PartialEq + Default> PartialEq for ItemPresent<T>
Source§fn eq(&self, other: &ItemPresent<T>) -> bool
fn eq(&self, other: &ItemPresent<T>) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl<T: PartialOrd + Default> PartialOrd for ItemPresent<T>
impl<T: PartialOrd + Default> PartialOrd for ItemPresent<T>
impl<T: PartialEq + Default> StructuralPartialEq for ItemPresent<T>
Auto Trait Implementations§
impl<T> Freeze for ItemPresent<T>where
T: Freeze,
impl<T> RefUnwindSafe for ItemPresent<T>where
T: RefUnwindSafe,
impl<T> Send for ItemPresent<T>where
T: Send,
impl<T> Sync for ItemPresent<T>where
T: Sync,
impl<T> Unpin for ItemPresent<T>where
T: Unpin,
impl<T> UnsafeUnpin for ItemPresent<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for ItemPresent<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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<R> CryptoRng for R
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>
Converts
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>
Converts
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)
Converts
&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)
Converts
&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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.impl<T> Formattable 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>
Converts
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>
Converts
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 moreimpl<T> Parsable for T
Source§impl<T> PossiblyOption<T> for T
impl<T> PossiblyOption<T> for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<R> RngCore for Rwhere
R: Rng,
Source§impl<T> RngExt for Twhere
T: Rng,
impl<T> RngExt for Twhere
T: Rng,
Source§fn gen_range_checked<T, R>(&mut self, range: R) -> Option<T>where
T: SampleUniform,
R: SampleRange<T>,
fn gen_range_checked<T, R>(&mut self, range: R) -> Option<T>where
T: SampleUniform,
R: SampleRange<T>,
Generate a random value in the given range. Read more
Source§fn gen_range_infallible<T>(&mut self, range: RangeToInclusive<T>) -> Twhere
T: GenRangeInfallible,
fn gen_range_infallible<T>(&mut self, range: RangeToInclusive<T>) -> Twhere
T: GenRangeInfallible,
Generate a random value in the given upper-bounded-only range. Read more
Source§impl<R> RngExt for R
impl<R> RngExt for R
Source§fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
Return a random value via the
StandardUniform distribution. Read moreSource§fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
Source§fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
Generate a random value in the given range. Read more
Source§fn random_bool(&mut self, p: f64) -> bool
fn random_bool(&mut self, p: f64) -> bool
Return a bool with a probability
p of being true. Read moreSource§fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
Return a bool with a probability of
numerator/denominator of being
true. Read moreSource§fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
Sample a new value, using the given distribution. Read more
Source§fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
Create an iterator that generates values using the given distribution. Read more