pub struct IgnoredAny;Expand description
An efficient way of discarding data from a deserializer.
Think of this like serde_json::Value in that it can be deserialized from
any type, except that it does not store any information about the data that
gets deserialized.
use serde::de::{
self, Deserialize, DeserializeSeed, Deserializer, IgnoredAny, SeqAccess, Visitor,
};
use std::fmt;
use std::marker::PhantomData;
/// A seed that can be used to deserialize only the `n`th element of a sequence
/// while efficiently discarding elements of any type before or after index `n`.
///
/// For example to deserialize only the element at index 3:
///
/// ```
/// NthElement::new(3).deserialize(deserializer)
/// ```
pub struct NthElement<T> {
n: usize,
marker: PhantomData<T>,
}
impl<T> NthElement<T> {
pub fn new(n: usize) -> Self {
NthElement {
n: n,
marker: PhantomData,
}
}
}
impl<'de, T> Visitor<'de> for NthElement<T>
where
T: Deserialize<'de>,
{
type Value = T;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
write!(
formatter,
"a sequence in which we care about element {}",
self.n
)
}
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where
A: SeqAccess<'de>,
{
// Skip over the first `n` elements.
for i in 0..self.n {
// It is an error if the sequence ends before we get to element `n`.
if seq.next_element::<IgnoredAny>()?.is_none() {
return Err(de::Error::invalid_length(i, &self));
}
}
// Deserialize the one we care about.
let nth = match seq.next_element()? {
Some(nth) => nth,
None => {
return Err(de::Error::invalid_length(self.n, &self));
}
};
// Skip over any remaining elements in the sequence after `n`.
while let Some(IgnoredAny) = seq.next_element()? {
// ignore
}
Ok(nth)
}
}
impl<'de, T> DeserializeSeed<'de> for NthElement<T>
where
T: Deserialize<'de>,
{
type Value = T;
fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
where
D: Deserializer<'de>,
{
deserializer.deserialize_seq(self)
}
}
// Deserialize only the sequence element at index 3 from this deserializer.
// The element at index 3 is required to be a string. Elements before and
// after index 3 are allowed to be of any type.
let s: String = NthElement::new(3).deserialize(deserializer)?;Trait Implementations§
Source§impl Clone for IgnoredAny
impl Clone for IgnoredAny
Source§fn clone(&self) -> IgnoredAny
fn clone(&self) -> IgnoredAny
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for IgnoredAny
impl Debug for IgnoredAny
Source§impl Default for IgnoredAny
impl Default for IgnoredAny
Source§fn default() -> IgnoredAny
fn default() -> IgnoredAny
Source§impl<'de> Deserialize<'de> for IgnoredAny
impl<'de> Deserialize<'de> for IgnoredAny
Source§fn deserialize<D>(
deserializer: D,
) -> Result<IgnoredAny, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<IgnoredAny, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl PartialEq for IgnoredAny
impl PartialEq for IgnoredAny
Source§impl<'de> Visitor<'de> for IgnoredAny
impl<'de> Visitor<'de> for IgnoredAny
Source§type Value = IgnoredAny
type Value = IgnoredAny
Source§fn expecting(&self, formatter: &mut Formatter<'_>) -> Result<(), Error>
fn expecting(&self, formatter: &mut Formatter<'_>) -> Result<(), Error>
Source§fn visit_bool<E>(
self,
x: bool,
) -> Result<<IgnoredAny as Visitor<'de>>::Value, E>
fn visit_bool<E>( self, x: bool, ) -> Result<<IgnoredAny as Visitor<'de>>::Value, E>
Source§fn visit_i64<E>(self, x: i64) -> Result<<IgnoredAny as Visitor<'de>>::Value, E>
fn visit_i64<E>(self, x: i64) -> Result<<IgnoredAny as Visitor<'de>>::Value, E>
i64. Read moreSource§fn visit_i128<E>(
self,
x: i128,
) -> Result<<IgnoredAny as Visitor<'de>>::Value, E>
fn visit_i128<E>( self, x: i128, ) -> Result<<IgnoredAny as Visitor<'de>>::Value, E>
i128. Read moreSource§fn visit_u64<E>(self, x: u64) -> Result<<IgnoredAny as Visitor<'de>>::Value, E>
fn visit_u64<E>(self, x: u64) -> Result<<IgnoredAny as Visitor<'de>>::Value, E>
u64. Read moreSource§fn visit_u128<E>(
self,
x: u128,
) -> Result<<IgnoredAny as Visitor<'de>>::Value, E>
fn visit_u128<E>( self, x: u128, ) -> Result<<IgnoredAny as Visitor<'de>>::Value, E>
u128. Read moreSource§fn visit_f64<E>(self, x: f64) -> Result<<IgnoredAny as Visitor<'de>>::Value, E>
fn visit_f64<E>(self, x: f64) -> Result<<IgnoredAny as Visitor<'de>>::Value, E>
f64. Read moreSource§fn visit_str<E>(self, s: &str) -> Result<<IgnoredAny as Visitor<'de>>::Value, E>where
E: Error,
fn visit_str<E>(self, s: &str) -> Result<<IgnoredAny as Visitor<'de>>::Value, E>where
E: Error,
Source§fn visit_none<E>(self) -> Result<<IgnoredAny as Visitor<'de>>::Value, E>
fn visit_none<E>(self) -> Result<<IgnoredAny as Visitor<'de>>::Value, E>
Source§fn visit_some<D>(
self,
deserializer: D,
) -> Result<<IgnoredAny as Visitor<'de>>::Value, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn visit_some<D>(
self,
deserializer: D,
) -> Result<<IgnoredAny as Visitor<'de>>::Value, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§fn visit_newtype_struct<D>(
self,
deserializer: D,
) -> Result<<IgnoredAny as Visitor<'de>>::Value, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn visit_newtype_struct<D>(
self,
deserializer: D,
) -> Result<<IgnoredAny as Visitor<'de>>::Value, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§fn visit_unit<E>(self) -> Result<<IgnoredAny as Visitor<'de>>::Value, E>
fn visit_unit<E>(self) -> Result<<IgnoredAny as Visitor<'de>>::Value, E>
(). Read moreSource§fn visit_seq<A>(
self,
seq: A,
) -> Result<<IgnoredAny as Visitor<'de>>::Value, <A as SeqAccess<'de>>::Error>where
A: SeqAccess<'de>,
fn visit_seq<A>(
self,
seq: A,
) -> Result<<IgnoredAny as Visitor<'de>>::Value, <A as SeqAccess<'de>>::Error>where
A: SeqAccess<'de>,
Source§fn visit_map<A>(
self,
map: A,
) -> Result<<IgnoredAny as Visitor<'de>>::Value, <A as MapAccess<'de>>::Error>where
A: MapAccess<'de>,
fn visit_map<A>(
self,
map: A,
) -> Result<<IgnoredAny as Visitor<'de>>::Value, <A as MapAccess<'de>>::Error>where
A: MapAccess<'de>,
Source§fn visit_bytes<E>(
self,
bytes: &[u8],
) -> Result<<IgnoredAny as Visitor<'de>>::Value, E>where
E: Error,
fn visit_bytes<E>(
self,
bytes: &[u8],
) -> Result<<IgnoredAny as Visitor<'de>>::Value, E>where
E: Error,
Source§fn visit_enum<A>(
self,
data: A,
) -> Result<<IgnoredAny as Visitor<'de>>::Value, <A as EnumAccess<'de>>::Error>where
A: EnumAccess<'de>,
fn visit_enum<A>(
self,
data: A,
) -> Result<<IgnoredAny as Visitor<'de>>::Value, <A as EnumAccess<'de>>::Error>where
A: EnumAccess<'de>,
Source§fn visit_i8<E>(self, v: i8) -> Result<Self::Value, E>where
E: Error,
fn visit_i8<E>(self, v: i8) -> Result<Self::Value, E>where
E: Error,
i8. Read moreSource§fn visit_i16<E>(self, v: i16) -> Result<Self::Value, E>where
E: Error,
fn visit_i16<E>(self, v: i16) -> Result<Self::Value, E>where
E: Error,
i16. Read moreSource§fn visit_i32<E>(self, v: i32) -> Result<Self::Value, E>where
E: Error,
fn visit_i32<E>(self, v: i32) -> Result<Self::Value, E>where
E: Error,
i32. Read moreSource§fn visit_u8<E>(self, v: u8) -> Result<Self::Value, E>where
E: Error,
fn visit_u8<E>(self, v: u8) -> Result<Self::Value, E>where
E: Error,
u8. Read moreSource§fn visit_u16<E>(self, v: u16) -> Result<Self::Value, E>where
E: Error,
fn visit_u16<E>(self, v: u16) -> Result<Self::Value, E>where
E: Error,
u16. Read moreSource§fn visit_u32<E>(self, v: u32) -> Result<Self::Value, E>where
E: Error,
fn visit_u32<E>(self, v: u32) -> Result<Self::Value, E>where
E: Error,
u32. Read moreSource§fn visit_f32<E>(self, v: f32) -> Result<Self::Value, E>where
E: Error,
fn visit_f32<E>(self, v: f32) -> Result<Self::Value, E>where
E: Error,
f32. Read moreSource§fn visit_char<E>(self, v: char) -> Result<Self::Value, E>where
E: Error,
fn visit_char<E>(self, v: char) -> Result<Self::Value, E>where
E: Error,
char. Read moreSource§fn visit_borrowed_str<E>(self, v: &'de str) -> Result<Self::Value, E>where
E: Error,
fn visit_borrowed_str<E>(self, v: &'de str) -> Result<Self::Value, E>where
E: Error,
Deserializer. Read moreSource§fn visit_string<E>(self, v: String) -> Result<Self::Value, E>where
E: Error,
fn visit_string<E>(self, v: String) -> Result<Self::Value, E>where
E: Error,
Visitor. Read moreimpl Copy for IgnoredAny
impl StructuralPartialEq for IgnoredAny
Auto Trait Implementations§
impl Freeze for IgnoredAny
impl RefUnwindSafe for IgnoredAny
impl Send for IgnoredAny
impl Sync for IgnoredAny
impl Unpin for IgnoredAny
impl UnwindSafe for IgnoredAny
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);