Skip to main content

Charset

Enum Charset 

Source
#[non_exhaustive]
pub enum Charset {
Show 44 variants Utf8, Utf7, Utf16, Utf16Le, Utf16Be, Iso8859_2, Iso8859_3, Iso8859_4, Iso8859_5, Iso8859_6, Iso8859_7, Iso8859_8, Iso8859_9, Iso8859_10, Iso8859_13, Iso8859_14, Iso8859_15, Iso8859_16, Windows1250, Windows1251, Windows1252, Windows1253, Windows1254, Windows1255, Windows1256, Windows1257, Windows1258, Koi8R, Koi8U, Macintosh, Ibm850, Tis620, ShiftJis, Big5, EucJp, EucKr, Gb18030, Gbk, Iso2022Jp, Windows874, Ibm866, XMacCyrillic, XUserDefined, Replacement,
}
Expand description

A charset that text can be converted from.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Utf8

UTF-8, also used for text without a charset or with an unknown one.

§

Utf7

UTF-7 (RFC 2152).

§

Utf16

UTF-16 with a byte order mark; little-endian without one.

§

Utf16Le

UTF-16, little-endian.

§

Utf16Be

UTF-16, big-endian.

§

Iso8859_2

ISO-8859-2 (Latin-2, Central European).

§

Iso8859_3

ISO-8859-3 (Latin-3, South European).

§

Iso8859_4

ISO-8859-4 (Latin-4, North European).

§

Iso8859_5

ISO-8859-5 (Cyrillic).

§

Iso8859_6

ISO-8859-6 (Arabic).

§

Iso8859_7

ISO-8859-7 (Greek).

§

Iso8859_8

ISO-8859-8 (Hebrew).

§

Iso8859_9

ISO-8859-9 (Latin-5, Turkish), strictly as the standard defines it. No label resolves here: iso-8859-9 and its aliases resolve to Charset::Windows1254, the superset senders actually send.

§

Iso8859_10

ISO-8859-10 (Latin-6, Nordic).

§

Iso8859_13

ISO-8859-13 (Latin-7, Baltic).

§

Iso8859_14

ISO-8859-14 (Latin-8, Celtic).

§

Iso8859_15

ISO-8859-15 (Latin-9).

§

Iso8859_16

ISO-8859-16 (Latin-10, South-Eastern European).

§

Windows1250

windows-1250 (Central European).

§

Windows1251

windows-1251 (Cyrillic).

§

Windows1252

windows-1252 (Western European), also used for the ISO-8859-1 and US-ASCII labels, as browsers do.

§

Windows1253

windows-1253 (Greek).

§

Windows1254

windows-1254 (Turkish).

§

Windows1255

windows-1255 (Hebrew).

§

Windows1256

windows-1256 (Arabic).

§

Windows1257

windows-1257 (Baltic).

§

Windows1258

windows-1258 (Vietnamese).

§

Koi8R

KOI8-R (Russian).

§

Koi8U

KOI8-U (Ukrainian).

§

Macintosh

Mac OS Roman.

§

Ibm850

IBM code page 850 (DOS Latin-1).

§

Tis620

TIS-620 (Thai), strictly as the standard defines it. No label resolves here: tis-620 and iso-8859-11 resolve to Charset::Windows874, the superset senders actually send.

§

ShiftJis

Shift_JIS (Japanese); needs the full_encoding feature.

§

Big5

Big5 (Traditional Chinese); needs the full_encoding feature.

§

EucJp

EUC-JP (Japanese); needs the full_encoding feature.

§

EucKr

EUC-KR (Korean); needs the full_encoding feature.

§

Gb18030

GB18030 (Simplified Chinese); needs the full_encoding feature.

§

Gbk

GBK (Simplified Chinese); needs the full_encoding feature.

§

Iso2022Jp

ISO-2022-JP (Japanese); needs the full_encoding feature.

§

Windows874

windows-874 (Thai). Also the target of the tis-620 and iso-8859-11 labels, since senders use them for code page 874 bytes.

§

Ibm866

IBM code page 866 (DOS Cyrillic); needs the full_encoding feature.

§

XMacCyrillic

x-mac-cyrillic; needs the full_encoding feature.

§

XUserDefined

x-user-defined; needs the full_encoding feature.

§

Replacement

The WHATWG replacement encoding, for labels of charsets that are not decoded on purpose (ISO-2022-KR, HZ-GB-2312, …): the text becomes one U+FFFD. Needs the full_encoding feature.

Implementations§

Source§

impl Charset

Source

pub fn from_label(label: &[u8]) -> Option<Charset>

The charset for a MIME or WHATWG label, ASCII case-insensitive; None for an unknown label.

Source

pub fn decode(self, bytes: &[u8]) -> Cow<'_, str>

Converts bytes to text; byte sequences that are not valid in the charset become U+FFFD. Borrowed when the bytes are already the text (valid UTF-8, or ASCII in a single-byte charset).

Source

pub fn decode_owned(self, bytes: Vec<u8>) -> String

Converts bytes to text like Charset::decode, reusing the vector when the bytes are already the text.

Source

pub fn decode_append(self, bytes: &[u8], out: &mut String)

Converts bytes like Charset::decode, appending the text to out.

Source

pub fn decode_checked(self, bytes: &[u8]) -> (Cow<'_, str>, bool)

Converts bytes to text like Charset::decode and reports whether any sequence was not valid in the charset.

Trait Implementations§

Source§

impl Clone for Charset

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Charset

Source§

impl Debug for Charset

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Charset

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Charset

Source§

impl Hash for Charset

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Charset

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Charset

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.