#[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
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
impl Charset
Sourcepub fn from_label(label: &[u8]) -> Option<Charset>
pub fn from_label(label: &[u8]) -> Option<Charset>
The charset for a MIME or WHATWG label, ASCII case-insensitive;
None for an unknown label.
Sourcepub fn decode(self, bytes: &[u8]) -> Cow<'_, str>
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).
Sourcepub fn decode_owned(self, bytes: Vec<u8>) -> String
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.
Sourcepub fn decode_append(self, bytes: &[u8], out: &mut String)
pub fn decode_append(self, bytes: &[u8], out: &mut String)
Converts bytes like Charset::decode, appending the text to
out.
Sourcepub fn decode_checked(self, bytes: &[u8]) -> (Cow<'_, str>, bool)
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.