Skip to main content

MultiByte

Enum MultiByte 

Source
#[non_exhaustive]
pub enum MultiByte { ShiftJis, EucJp, Iso2022Jp, Gbk, Gb18030, Big5, EucKr, }
Expand description

A multi-byte encoding of the WHATWG Encoding Standard: the legacy encodings of Chinese, Japanese and Korean text that browsers, mail and old files still use. Each is the standard’s: the Windows variants where the web uses them (Shift_JIS is Windows’ code page 932, EUC-KR its 949, GBK its 936).

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

ShiftJis

Shift_JIS: Japanese as Windows writes it (code page 932, windows-31j: JIS X 0208 with the NEC and IBM extensions, half-width katakana, the user-defined rows as the Private Use Area)

§

EucJp

EUC-JP: Japanese on Unix (JIS X 0208, JIS X 0212 after 0x8F, half-width katakana after 0x8E)

§

Iso2022Jp

ISO-2022-JP: Japanese in mail and news, 7 bits with escape sequences (ASCII, JIS X 0201 Roman and katakana, JIS X 0208)

§

Gbk

GBK: simplified Chinese (code page 936; also what the labels gb2312 and chinese name). It reads gb18030; it writes only its two-byte characters and the euro sign as 0x80.

§

Gb18030

gb18030: simplified Chinese with all of Unicode but U+E5E5, which it does not write (GB18030-2022; code page 54936)

§

Big5

Big5: traditional Chinese with the Hong Kong Supplementary Character Set (HKSCS-2008; code page 950)

§

EucKr

EUC-KR: Korean as Windows writes it (code page 949, the Unified Hangul Code: all 11 172 syllables)

Implementations§

Source§

impl MultiByte

Source

pub const ALL: &'static [MultiByte]

every multi-byte encoding, in declaration order

Source

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

its name in the WHATWG Encoding Standard (“Shift_JIS”, “EUC-JP”, “ISO-2022-JP”, “GBK”, “gb18030”, “Big5”, “EUC-KR”)

Source

pub const fn code_page(self) -> u16

its Windows code page number: 932, 20932, 50220, 936, 54936, 950, 949

Source

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

the encoding of a Windows code page number: 932, 936, 949, 950, 20932 and 51932 (EUC-JP), 50220 and 50221 (ISO-2022-JP), 51949 (EUC-KR), 54936. None for the others: Johab (1361) is none of the standard’s, and 50222 writes half-width katakana between SO and SI, which the standard’s ISO-2022-JP does not read.

Source

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

the encoding a WHATWG label names (“shift_jis”, “sjis”, “windows-31j”, “gb2312”, “big5-hkscs”, “ks_c_5601-1987” …; encoding::label), multi-byte encodings only

Source

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

The text of these bytes, as the standard decodes them: malformed or unassigned sequences become U+FFFD, ASCII bytes after a broken lead byte are kept. For input in pieces: Decoder.

Source

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

The bytes of a text; Unmappable: the first character this encoding does not have (ISO-2022-JP ends in ASCII, with ESC ( B where needed).

Source

pub fn encode_html(self, text: &str) -> Vec<u8> ⓘ

The bytes of a text, a character this encoding does not have as a decimal character reference (“😀”), as browsers submit forms (the standard’s “html” error mode).

Trait Implementations§

Source§

impl Clone for MultiByte

Source§

fn clone(&self) -> MultiByte

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 MultiByte

Source§

impl Debug for MultiByte

Source§

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

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

impl Eq for MultiByte

Source§

impl Hash for MultiByte

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 MultiByte

Source§

fn cmp(&self, other: &MultiByte) -> 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 MultiByte

Source§

fn eq(&self, other: &MultiByte) -> 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 MultiByte

Source§

fn partial_cmp(&self, other: &MultiByte) -> 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 MultiByte

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.