Struct DecodedString

Source
pub struct DecodedString {
    pub encoding: &'static dyn Encoding,
    pub characters: Vec<DecodedCharacter>,
}
Expand description

A string that has been decoded using a particular character encoding.

Fields§

§encoding: &'static dyn Encoding§characters: Vec<DecodedCharacter>

Implementations§

Source§

impl DecodedString

Source

pub fn decode( string: &[u8], encoding: EncodingRef, ) -> Result<DecodedString, Cow<'static, str>>

Decode a sequence of bytes using a particular encoding.

Any characters that cannot be encoded will be represented using unicode replacement characters (U+FFFD).

§Errors

Returns an error if anything goes wrong with the underlying decoder. This shouldn’t actually happen(?)

Source

pub fn format_bytes(&self) -> String

Format the byte representation of the string using hex.

Source

pub fn format_characters(&self) -> String

Format the string in an easy to understand way. ASCII characters are rendered normally. Tabs, carriage returns and newlines are represented as escape sequences. All other characters are rendered as their unicode codepoints.

§Limitations

This is not guaranteed to work properly if codepoints in hex are longer than the number of bytes used to represent it in the encoding; for example, latin characters in UTF-16.

Source

pub fn to_string(&self) -> String

Convert to a regular string.

Source

pub fn wrap_lines(&self, max_line_width: usize) -> Vec<DecodedString>

Split into chunks so that the output of format_bytes and format_characters fit within max_line_width characters for each chunk.

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.