Struct jomini::TextTape

source ·
pub struct TextTape<'a> { /* private fields */ }
Expand description

Houses the tape of tokens that is extracted from plaintext data

Implementations§

Creates a windows 1252 object reader from the parsed tape

Examples found in repository?
src/text/writer.rs (line 512)
508
509
510
511
512
513
514
515
    pub fn write_tape(&mut self, tape: &TextTape) -> Result<(), Error> {
        // it doesn't actually matter the encoding that is chosen as everything
        // will be blindly written out and we don't need to know the encoding
        // for that.
        let reader = tape.windows1252_reader();
        self.write_object_core(reader)?;
        Ok(())
    }

Creates a utf-8 object reader from the parsed tape

Creates a new text tape

Convenience method for creating a text parser and parsing the given input

Examples found in repository?
src/text/de.rs (line 181)
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
    pub fn from_windows1252_slice<'a, T>(data: &'a [u8]) -> Result<T, Error>
    where
        T: Deserialize<'a>,
    {
        let tape = TextTape::from_slice(data)?;
        TextDeserializer::from_windows1252_tape(&tape)
    }

    /// Deserialize the given text tape assuming quoted strings are windows1252 encoded.
    pub fn from_windows1252_tape<'a, T>(tape: &TextTape<'a>) -> Result<T, Error>
    where
        T: Deserialize<'a>,
    {
        Self::from_encoded_tape(tape, Windows1252Encoding::new())
    }

    /// Convenience method for parsing the given text data and deserializing as utf8 encoded.
    pub fn from_utf8_slice<'a, T>(data: &'a [u8]) -> Result<T, Error>
    where
        T: Deserialize<'a>,
    {
        let tape = TextTape::from_slice(data)?;
        TextDeserializer::from_utf8_tape(&tape)
    }

Returns a parser for text data

Return the parsed tokens

Examples found in repository?
src/text/reader.rs (line 541)
540
541
542
543
544
545
546
547
548
    pub fn new(tape: &'tokens TextTape<'data>, encoding: E) -> Self {
        let tokens = tape.tokens();
        ObjectReader {
            tokens,
            end_ind: tokens.len(),
            start_ind: 0,
            encoding,
        }
    }

Return if there was a UTF8 BOM in the data

Trait Implementations§

Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

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 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.