Struct jomini::Utf8Encoding

source ·
pub struct Utf8Encoding;
Expand description

Decodes bytes according to the utf8 standard

use jomini::{Utf8Encoding, Encoding};

let encoding = Utf8Encoding::new();
assert_eq!(encoding.decode(b"Common Sense"), "Common Sense");
assert_eq!(encoding.decode(br#"Captain \"Joe\" Rogers"#), r#"Captain "Joe" Rogers"#);
assert_eq!(encoding.decode(b"1444.11.11\n"), "1444.11.11");
assert_eq!(encoding.decode(b"J\xc3\xa5hk\xc3\xa5m\xc3\xa5hkke"), "Jåhkåmåhkke");
assert_eq!(encoding.decode("Jåhkåmåhkke".as_bytes()), "Jåhkåmåhkke");

Implementations§

Creates a new utf8 decoder

Examples found in repository?
src/text/tape.rs (line 169)
168
169
170
    pub fn utf8_reader(&self) -> ObjectReader<Utf8Encoding> {
        ObjectReader::new(self, Utf8Encoding::new())
    }
More examples
Hide additional examples
src/text/de.rs (line 207)
203
204
205
206
207
208
    pub fn from_utf8_tape<'a, 'b, T>(tape: &'b TextTape<'a>) -> Result<T, Error>
    where
        T: Deserialize<'a>,
    {
        Self::from_encoded_tape(tape, Utf8Encoding::new())
    }

Static method for decoding utf8 data

Examples found in repository?
src/encoding.rs (line 106)
105
106
107
    fn decode<'a>(&self, data: &'a [u8]) -> Cow<'a, str> {
        Utf8Encoding::decode(data)
    }

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
Returns the “default value” for a type. Read more
Decodes bytes into a utf-8 compatible string – allocating if necessary

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