Skip to main content

Utf16

Enum Utf16 

Source
pub enum Utf16 {}
Expand description

Namespace for UTF-16 constants and code-unit classification helpers.

Implementations§

Source§

impl Utf16

Source

pub const MAX_UNITS_PER_CHAR: usize = 2

Maximum number of UTF-16 code units needed for one Unicode scalar value.

Source

pub const MAX_BYTES_PER_CHAR: usize = 4

Maximum number of serialized UTF-16 bytes needed for one Unicode scalar value.

Source

pub const fn is_high_surrogate(unit: u16) -> bool

Tests whether a UTF-16 unit is a high surrogate.

§Parameters
  • unit: The UTF-16 unit to test.
§Returns

Returns true if unit is in 0xD800..=0xDBFF.

Source

pub const fn is_low_surrogate(unit: u16) -> bool

Tests whether a UTF-16 unit is a low surrogate.

§Parameters
  • unit: The UTF-16 unit to test.
§Returns

Returns true if unit is in 0xDC00..=0xDFFF.

Source

pub const fn is_surrogate(unit: u16) -> bool

Tests whether a UTF-16 unit is any surrogate.

§Parameters
  • unit: The UTF-16 unit to test.
§Returns

Returns true if unit is in 0xD800..=0xDFFF.

Source

pub const fn is_single_unit(unit: u16) -> bool

Tests whether a UTF-16 unit encodes a scalar value by itself.

§Parameters
  • unit: The UTF-16 unit to test.
§Returns

Returns true for non-surrogate units.

Source

pub const fn is_surrogate_pair(high: u16, low: u16) -> bool

Tests whether two UTF-16 units form a surrogate pair.

§Parameters
  • high: The candidate high surrogate.
  • low: The candidate low surrogate.
§Returns

Returns true if high is a high surrogate and low is a low surrogate.

Source

pub const fn unit_len(ch: char) -> usize

Returns the UTF-16 unit count needed for ch.

§Parameters
  • ch: The character to size.
§Returns

Returns 1 for BMP scalar values and 2 for supplementary scalar values.

Source

pub const fn unit_len_code_point(code_point: u32) -> Option<usize>

Returns the UTF-16 unit count needed for a raw code point.

§Parameters
  • code_point: The raw code point to size.
§Returns

Returns Some(1) or Some(2) for scalar values and None otherwise.

Source

pub const fn compose_pair(high: u16, low: u16) -> Option<u32>

Composes a surrogate pair into a Unicode code point.

§Parameters
  • high: The high surrogate.
  • low: The low surrogate.
§Returns

Returns Some(code_point) when the pair is valid, or None otherwise.

Source

pub const fn high_surrogate(code_point: u32) -> Option<u16>

Returns the high surrogate for a supplementary code point.

§Parameters
  • code_point: The supplementary code point.
§Returns

Returns Some(high_surrogate) for supplementary code points and None otherwise.

Source

pub const fn low_surrogate(code_point: u32) -> Option<u16>

Returns the low surrogate for a supplementary code point.

§Parameters
  • code_point: The supplementary code point.
§Returns

Returns Some(low_surrogate) for supplementary code points and None otherwise.

Source

pub fn detect_bom(bytes: &[u8]) -> Option<ByteOrder>

Detects a UTF-16 BOM and returns its byte order.

§Parameters
  • bytes: The byte buffer to inspect.
§Returns

Returns Some(ByteOrder) for UTF-16 BOM prefixes, or None otherwise.

Auto Trait Implementations§

§

impl Freeze for Utf16

§

impl RefUnwindSafe for Utf16

§

impl Send for Utf16

§

impl Sync for Utf16

§

impl Unpin for Utf16

§

impl UnsafeUnpin for Utf16

§

impl UnwindSafe for Utf16

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