Skip to main content

Charset

Struct Charset 

Source
pub struct Charset { /* private fields */ }
Expand description

Identifies the charset associated with a codec or error.

A charset is represented by a stable normalized identifier, a display name, and accepted aliases. Equality and hashing use only the identifier, so display names and alias lists can evolve without changing identity.

§Examples

use qubit_codec_text::Charset;

const GBK: Charset = Charset::new("gbk", "GBK", &["cp936"]);

assert!(GBK.matches_label("CP936"));
assert_eq!(GBK, Charset::new("gbk", "Chinese GBK", &[]));
assert_eq!("GBK", GBK.to_string());

Implementations§

Source§

impl Charset

Source

pub const ASCII: Self

US-ASCII text.

Source

pub const ISO_8859_1: Self

ISO-8859-1 / Latin-1 text.

Source

pub const UTF_8: Self

UTF-8 text.

Source

pub const UTF_16: Self

UTF-16 text.

Source

pub const UTF_16LE: Self

UTF-16 text serialized in little-endian byte order.

Source

pub const UTF_16BE: Self

UTF-16 text serialized in big-endian byte order.

Source

pub const UTF_32: Self

UTF-32 text.

Source

pub const UTF_32LE: Self

UTF-32 text serialized in little-endian byte order.

Source

pub const UTF_32BE: Self

UTF-32 text serialized in big-endian byte order.

Source

pub const BUILTINS: &'static [Self]

Built-in charsets known by this crate.

Source

pub const fn new( id: &'static str, name: &'static str, aliases: &'static [&'static str], ) -> Self

Creates a charset descriptor.

§Parameters
  • id: Stable normalized identifier used for equality and hashing.
  • name: Human-readable display name.
  • aliases: Additional labels accepted for this charset.
§Returns

Returns a charset descriptor carrying the supplied metadata.

Source

pub fn from_label(label: &str) -> Option<Self>

Finds a built-in charset by label.

§Parameters
  • label: Charset label to match against built-in identifiers, names, and aliases.
§Returns

Returns Some(Charset) when label names one of this crate’s built-in charsets, or None when no built-in charset matches. Custom descriptors created with Self::new are not part of this lookup. Leading and trailing ASCII whitespace is ignored before matching.

Source

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

Returns the stable normalized charset identifier.

§Returns

Returns the identifier used for equality and hashing.

Source

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

Returns a human-readable charset label.

§Returns

Returns the display name stored in this descriptor.

Source

pub const fn aliases(self) -> &'static [&'static str]

Returns accepted aliases for this charset.

§Returns

Returns the static alias list stored in this descriptor.

Source

pub const fn from_utf16_byte_order(byte_order: ByteOrder) -> Self

Returns the UTF-16 charset with a fixed byte order.

§Parameters
  • byte_order: The byte order used by the byte stream.
§Returns

Returns Self::UTF_16LE for little-endian byte order and Self::UTF_16BE for big-endian byte order.

Source

pub const fn from_utf32_byte_order(byte_order: ByteOrder) -> Self

Returns the UTF-32 charset with a fixed byte order.

§Parameters
  • byte_order: The byte order used by the byte stream.
§Returns

Returns Self::UTF_32LE for little-endian byte order and Self::UTF_32BE for big-endian byte order.

Source

pub fn byte_order(self) -> Option<ByteOrder>

Returns the fixed byte order represented by this charset.

§Returns

Returns Some(ByteOrder) for fixed-endian UTF-16 and UTF-32 charsets. Returns None for UTF-8 and generic UTF-16/UTF-32 charsets.

Source

pub fn matches_label(self, label: &str) -> bool

Tests whether a label names this charset.

§Parameters
  • label: The label to compare with this descriptor’s identifier, display name, and aliases.
§Returns

Returns true when label matches the identifier, display name, or one of the aliases using ASCII case-insensitive comparison.

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

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

impl Display for Charset

Source§

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

Formats this charset label.

§Parameters
  • formatter: The formatter receiving the label.
§Errors

Returns any formatting error reported by formatter.

Source§

impl Eq for Charset

Source§

impl Hash for Charset

Source§

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

Hashes the stable encoding identifier.

§Parameters
  • state: The hasher receiving this encoding’s identity.
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

Compares charsets by stable identifier.

§Parameters
  • other: The descriptor to compare against.
§Returns

Returns true when both descriptors have the same identifier.

1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.