PrintingTokenSink

Struct PrintingTokenSink 

Source
pub struct PrintingTokenSink<'a: 'b, 'b, S: TokenSink, W: Write> { /* private fields */ }
Expand description

A token sink that prints a description of the tokens to a writer, and forwards them to another sink. For debugging.

Each token is output on one line. Start and end tokens adjust indentation.

§Example

let mut got = TokenVec::new();
let mut output = Vec::new();
vec![42u32]
    .into_tokens(&mut PrintingTokenSink::new(&mut got, &mut output, "T: "))
    .unwrap();
assert_eq!(
    String::from_utf8(output).unwrap(),
    concat!(
        "T: Seq(SeqMeta { size_hint: Some(1) })\n",
        "T:   U32(42)\n",
        "T: EndSeq\n")
);

Implementations§

Source§

impl<'a: 'b, 'b, S: TokenSink, W: Write> PrintingTokenSink<'a, 'b, S, W>

Source

pub fn new(sink: &'b mut S, writer: W, prefix: &'a str) -> Self

Creates a new printing sink. The prefix is used for each output line, before the indentation.

Trait Implementations§

Source§

impl<'a: 'b, 'b, S: TokenSink, W: Write> TokenSink for PrintingTokenSink<'a, 'b, S, W>

Source§

type Error = PrintError<<S as TokenSink>::Error>

Source§

fn yield_token(&mut self, token: Token<'_>) -> Result<bool, Self::Error>

Handles the next token from the stream. Returns true if the sink requires more tokens.
Source§

fn expect_tokens(&mut self) -> Option<TokenTypes>

Returns the set of token types expected next. The Self::yield_token function may accept or refuse any token; this is an optional type negotation mechanism. E.g. if String isn’t expected, but U32 is, then the source may choose to do a conversion. In general, sources should not expect sinks to do type conversions. Read more
Source§

fn into_any(self: Box<Self>) -> Box<dyn Any>

Converts the boxed sink into a boxed Any. This is used in the FromTokens derive macro to support dynamic dispatch for fields and variants. It only needs to be overridden for types where Self::yield_token returns true. Read more

Auto Trait Implementations§

§

impl<'a, 'b, S, W> Freeze for PrintingTokenSink<'a, 'b, S, W>
where W: Freeze,

§

impl<'a, 'b, S, W> RefUnwindSafe for PrintingTokenSink<'a, 'b, S, W>

§

impl<'a, 'b, S, W> Send for PrintingTokenSink<'a, 'b, S, W>
where W: Send, S: Send,

§

impl<'a, 'b, S, W> Sync for PrintingTokenSink<'a, 'b, S, W>
where W: Sync, S: Sync,

§

impl<'a, 'b, S, W> Unpin for PrintingTokenSink<'a, 'b, S, W>
where W: Unpin,

§

impl<'a, 'b, S, W> !UnwindSafe for PrintingTokenSink<'a, 'b, S, W>

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.