Struct parsel::util::SpanDisplay

source ·
pub struct SpanDisplay { /* private fields */ }
Expand description

Helper type that formats a Span in a human-readable way.

#[derive(Clone, Debug, Parse)]
struct HttpHeader {
    key: Separated<Word, Token![-]>,
    colon: Token![:],
    value: TokenStream,
}

let header: HttpHeader = parsel::parse_str(r#"
    // this comment exists only so that there is a line before the actual tokens
    Content-Type: application/json
    /* another comment, just to confuse the lexer */
"#)?;

let key_span = header.key.format_span().to_string();
assert_eq!(key_span, "3:5..3:16");

let colon_span = header.colon.format_span().to_string();
assert_eq!(colon_span, "3:17..3:17");

let value_span = header.value.format_span().to_string();
assert_eq!(value_span, "3:19..3:34");

Implementations

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.