Skip to main content

Charset

Enum Charset 

Source
#[non_exhaustive]
pub enum Charset {
Show 45 variants Ibm866, Iso8859_2, Iso8859_3, Iso8859_4, Iso8859_5, Iso8859_6, Iso8859_7, Iso8859_8, Iso8859_8I, Iso8859_10, Iso8859_13, Iso8859_14, Iso8859_15, Iso8859_16, Koi8R, Koi8U, Macintosh, Windows874, Windows1250, Windows1251, Windows1252, Windows1253, Windows1254, Windows1255, Windows1256, Windows1257, Windows1258, XMacCyrillic, XUserDefined, Latin1, Ibm437, Ibm737, Ibm775, Ibm850, Ibm852, Ibm855, Ibm857, Ibm858, Ibm860, Ibm861, Ibm862, Ibm863, Ibm864, Ibm865, Ibm869,
}
Expand description

a single-byte character set: the bytes below 0x80 are ASCII, the others come from its table. The single-byte encodings of the WHATWG Encoding Standard (what browsers, HTML and mail use; whatwg()) and the DOS code pages of old files (by from_code_page or by name here; no web label names them)

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

Ibm866

IBM866: DOS Cyrillic

§

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, visual order

§

Iso8859_8I

ISO-8859-8-I: Hebrew, logical order (the same bytes as ISO-8859-8)

§

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, Latin 1 with the euro sign

§

Iso8859_16

ISO-8859-16: Latin 10, South-Eastern European

§

Koi8R

KOI8-R: Russian

§

Koi8U

KOI8-U: Ukrainian and Belarusian (WHATWG’s KOI8-RU)

§

Macintosh

macintosh: Mac OS Roman

§

Windows874

windows-874: Thai (also TIS-620 and ISO-8859-11)

§

Windows1250

windows-1250: Windows Central European

§

Windows1251

windows-1251: Windows Cyrillic

§

Windows1252

windows-1252: Windows Western (also ISO-8859-1 and ASCII on the web)

§

Windows1253

windows-1253: Windows Greek

§

Windows1254

windows-1254: Windows Turkish (also ISO-8859-9)

§

Windows1255

windows-1255: Windows Hebrew

§

Windows1256

windows-1256: Windows Arabic

§

Windows1257

windows-1257: Windows Baltic

§

Windows1258

windows-1258: Windows Vietnamese

§

XMacCyrillic

x-mac-cyrillic: Mac OS Cyrillic

§

XUserDefined

x-user-defined: bytes 0x80..0xFF as U+F780..U+F7FF (WHATWG)

§

Latin1

ISO-8859-1: ISO-8859-1 exactly: each byte is its code point (the web reads the label as windows-1252) (not WHATWG)

§

Ibm437

IBM437: DOS United States (also ZIP names without the UTF-8 flag) (not WHATWG)

§

Ibm737

IBM737: DOS Greek (not WHATWG)

§

Ibm775

IBM775: DOS Baltic (not WHATWG)

§

Ibm850

IBM850: DOS Western European (not WHATWG)

§

Ibm852

IBM852: DOS Central European (not WHATWG)

§

Ibm855

IBM855: DOS Cyrillic (IBM) (not WHATWG)

§

Ibm857

IBM857: DOS Turkish (not WHATWG)

§

Ibm858

IBM00858: DOS Western European with the euro sign (not WHATWG)

§

Ibm860

IBM860: DOS Portuguese (not WHATWG)

§

Ibm861

IBM861: DOS Icelandic (not WHATWG)

§

Ibm862

IBM862: DOS Hebrew (not WHATWG)

§

Ibm863

IBM863: DOS Canadian French (not WHATWG)

§

Ibm864

IBM864: DOS Arabic (not WHATWG)

§

Ibm865

IBM865: DOS Nordic (not WHATWG)

§

Ibm869

IBM869: DOS Greek 2 (not WHATWG)

Implementations§

Source§

impl Charset

Source

pub const ALL: &'static [Charset]

every character set, in declaration order

Source

pub const fn name(self) -> &'static str

its name: the WHATWG Encoding Standard’s, else IANA’s (“IBM437”, “ISO-8859-1”)

Source

pub const fn whatwg(self) -> bool

whether it is one of the WHATWG Encoding Standard’s encodings (the others have no web label)

Source

pub const fn code_page(self) -> Option<u16>

its Windows code page number (None: ISO-8859-10, -14 and -16 and x-user-defined have none)

Source

pub const fn from_code_page(cp: u16) -> Option<Charset>

the character set of a Windows code page number: 437 to 869 (DOS), 874, 1250 to 1258, 10000 and 10007 (Mac), 20866 and 21866 (KOI8), 28591 to 28605 (ISO-8859; 28599, ISO-8859-9, is windows-1254 as on the web), 38598

Source§

impl Charset

Source

pub fn from_label(name: &str) -> Option<Charset>

The character set a WHATWG label names (label, single-byte sets only): “windows-1252”, “latin1”, “koi8-r”, “cp1251”, “iso8859-2” … The DOS code pages and the exact ISO-8859-1 have no web label: from_code_page or the variant.

Source

pub fn decode(self, bytes: &[u8]) -> String

The text of these bytes; an unassigned byte becomes U+FFFD.

Source

pub fn decode_char(self, b: u8) -> Option<char>

The character of one byte (None: unassigned in this set).

Source

pub fn encode_char(self, c: char) -> Option<u8>

The byte of one character (None: not in this set; the first byte where a set has two).

Source

pub fn encode(self, text: &str) -> Result<Vec<u8>, Error>

The bytes of a text; Unmappable: the first character this set does not have.

Trait Implementations§

Source§

impl Clone for Charset

Source§

fn clone(&self) -> Charset

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<(), Error>

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

impl Eq for Charset

Source§

impl Hash for Charset

Source§

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

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 Ord for Charset

Source§

fn cmp(&self, other: &Charset) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for Charset

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialOrd for Charset

Source§

fn partial_cmp(&self, other: &Charset) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= 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.