Skip to main content

Char

Struct Char 

Source
pub struct Char<T>(pub T);
Expand description

๐“ ๐Ÿ› ๏ธ Unicode scalars-related low-level const operations.


๐Ÿ“ text/unicode/scalar


ยงTerminology

  • A code point is an integer in U+0000..=U+10FFFF.
  • A surrogate is a code point in U+D800..=U+DFFF.
  • A Unicode scalar value is a code point that is not a surrogate. Rustโ€™s char represents exactly this set.
  • A scalar rank is the zero-based position of a scalar value in the ordered set of all Unicode scalar values, with the surrogate range omitted.

ยงMethods

See also Str.

Tuple Fieldsยง

ยง0: T

Implementationsยง

Sourceยง

impl Char<char>

ยงMethods over char

Source

pub const fn len_utf8(self) -> usize

Returns the number of bytes needed to encode the given Unicode scalar as UTF-8.

See also Char::<u32>len_utf8.

Source

pub const fn width(self) -> usize

Returns the monospace display width.

  • 0: Non-printing characters (controls, combining marks)
  • 1: Regular characters (Latin, Greek, Cyrillic, etc.)
  • 2: Wide characters (CJK, emoji, fullwidth forms)
Source

pub const fn width_common(self) -> usize

Returns the monospace display width using faster calculation.

Uses optimized checks that cover common cases but may incorrectly report some obscure Unicode characters as 1 width instead of 2.

Source

pub const fn is_combining(self) -> bool

Returns true for all Unicode combining characters.

Includes musical notation, historic scripts, and obscure diacritics. Comprehensive but slightly slower than is_combining_common.

Source

pub const fn is_combining_common(self) -> bool

Returns true for common combining marks used in modern text.

Covers Latin, Greek, and most European language diacritics. Fast and suitable for 95% of use cases.

Source

pub const fn is_control(self) -> bool

Returns true for all Unicode control characters.

Source

pub const fn is_control_common(self) -> bool

Returns true for common Unicode control characters.

Just ASCII, zero-width spaces, bidi formatting, word joiners and invisible operators.

Source

pub const fn is_fullwidth(self) -> bool

Returns true for all Unicode fullwidth characters.

Source

pub const fn is_fullwidth_common(self) -> bool

Returns true for common fullwidth characters (ASCII variants, basic CJK)

Source

pub const fn to_utf8_bytes(self) -> [u8; 4]

Converts this Unicode scalar to a UTF-8 encoded byte sequence.

Always returns a [u8; 4] array, with unused bytes set to 0.

See also char::encode_utf8.

Source

pub const fn write_utf8_to(self, buf: &mut [u8]) -> usize

Writes this Unicode scalar as UTF-8 into buf.

Returns the number of bytes written.

A buffer of 4 bytes is always large enough for any Unicode scalar.

ยงPanics

Panics if buf.len() < self.0.len_utf8().

Source

pub const fn as_ascii(self) -> &'static str โ“˜

Returns the ASCII representation as a &'static str, or "" if non-ASCII.

Source

pub const fn as_ascii_unchecked(self) -> &'static str โ“˜

Returns the ASCII representation as a &'static str.

ยงPanics

Panics if the character is not ASCII.

Source

pub const fn to_ascii_fold(self) -> Option<char> โ“˜

Converts a character to its closest ASCII equivalent, if possible.

This function attempts to replace accented or special characters with their ASCII counterparts. If a mapping exists, it returns Some(char), otherwise, it returns None.

Source

pub const fn to_ascii_fold_unchecked(self) -> char

Converts a character to its closest ASCII equivalent, or returns the input character if no mapping exists.

This function is similar to to_ascii_fold, but never returns None. If no ASCII equivalent exists, the input character is returned unchanged.

Source

pub const fn random_next(rng: &mut Pcg32) -> char

Returns a Unicode scalar selected from the next output of rng.

Source

pub const fn random_from_seed(seed: u64) -> char

Returns a Unicode scalar deterministically selected from seed.

Sourceยง

impl Char<u16>

ยงMethods over u16.

Source

pub const fn is_surrogate(self) -> bool

Returns true if the given Unicode scalar code is a surrogate code point.

Source

pub const fn is_surrogate_high(self) -> bool

Returns true if the given Unicode scalar code is a leading surrogate.

Source

pub const fn is_surrogate_low(self) -> bool

Returns true if the given Unicode scalar code is a trailing surrogate.

Source

pub const fn decode_surrogate_pair(high: u16, low: u16) -> Option<char> โ“˜

Decodes the given surrogate pair.

ยงFeatures

Uses the unsafe_str feature to skip duplicated validation checks.

Sourceยง

impl Char<u32>

ยงMethods over u32.

Source

pub const MAX_CODE_POINT: u32 = 0x10_FFFF

Maximum Unicode code point.

Source

pub const SCALAR_COUNT: u32

Number of Unicode scalar values.

Source

pub const SURROGATE_COUNT: u32

Number of Unicode surrogate code points.

Source

pub const SURROGATE_START: u32 = 0xD800

First Unicode surrogate code point.

Source

pub const SURROGATE_END: u32 = 0xDFFF

Last Unicode surrogate code point.

Source

pub const SURROGATE_HIGH_END: u32 = 0xDBFF

Last high-surrogate code point, also called a leading surrogate.

Source

pub const SURROGATE_LOW_START: u32 = 0xDC00

First low-surrogate code point, also called a trailing surrogate.

Source

pub const fn scalar_from_rank(rank: u32) -> u32

Maps a dense Unicode scalar rank to its scalar value.

Scalar indices are contiguous in 0..SCALAR_COUNT, with the surrogate range omitted from the resulting values.

ยงPanics

Panics if rank >= SCALAR_COUNT.

Source

pub const fn scalar_rank(self) -> Option<u32> โ“˜

Returns the dense scalar rank of this value, or None if it is not a Unicode scalar value.

Source

pub const fn is_valid_code(self) -> bool

Checks whether the value is a Unicode code point.

A valid Unicode code point is any integer in the range: 0..=MAX_CODE_POINT.

This includes surrogate code points which are valid code points but cannot be represented as Unicode scalars.

ยงExamples
assert!(Char('A' as u32).is_valid_code()); // regular character
assert!(Char(0x00).is_valid_code());       // NULL is valid
assert!(Char(0x10FFFF).is_valid_code());   // maximum Unicode code point
// surrogates are valid code points:
assert!(Char(0xD800).is_valid_code());     // high surrogate
assert!(Char(0xDFFF).is_valid_code());     // low surrogate
// invalid:
assert!(!Char(0x110000).is_valid_code());  // above max Unicode
Source

pub const fn is_valid_scalar(self) -> bool

Checks whether the value is a Unicode scalar value representable as char.

This excludes surrogate code points, which are invalid in UTF-8 and cannot be represented as Unicode scalars.

ยงExamples
assert!(Char('A' as u32).is_valid_scalar()); // regular character
assert!(Char(0x00).is_valid_scalar());       // NULL is valid
assert!(Char(0x10FFFF).is_valid_scalar());   // maximum Unicode scalar
// invalid:
assert!(!Char(0xD800).is_valid_scalar());    // high surrogate
assert!(!Char(0xDFFF).is_valid_scalar());    // low surrogate
assert!(!Char(0x110000).is_valid_scalar());  // above max Unicode
Source

pub const fn is_surrogate(self) -> bool

Returns true if the value is a Unicode surrogate code point.

Source

pub const fn is_surrogate_high(self) -> bool

Returns true if the value is a Unicode high surrogate code point.

Source

pub const fn is_surrogate_low(self) -> bool

Returns true if the value is a Unicode low surrogate code point.

Source

pub const fn len_bytes(self) -> usize

Returns the bytes required to store the given Unicode code point in a non-UTF encoding.

This function does not determine the UTF-8 byte length. It assumes a simple encoding where values up to 0xFF use 1 byte, 0x100..=0xFFFF use 2 bytes, and anything larger uses 3 bytes.

Source

pub const fn len_utf8(self) -> Option<usize> โ“˜

Returns the number of bytes required to encode the given Unicode scalar as UTF-8.

Returns None if itโ€™s not a valid Unicode scalar.

Source

pub const fn len_utf8_unchecked(self) -> usize

Returns the UTF-8 byte length of the current Unicode scalar without validation.

Assumes the code is a valid Unicode scalar. Use len_utf8 for a checked version.

Source

pub const fn width(self) -> usize

Returns the monospace display width.

  • 0: Non-printing characters (controls, combining marks)
  • 1: Regular characters (Latin, Greek, Cyrillic, etc.)
  • 2: Wide characters (CJK, emoji, fullwidth forms)
Source

pub const fn width_common(self) -> usize

Returns the monospace display width using faster calculation.

Uses optimized checks that cover common cases but may incorrectly report some obscure Unicode characters as 1 width instead of 2.

Source

pub const fn is_ascii(self) -> bool

Checks if the given value is a 7-bit ASCII character (U+0000..=U+007F).

Source

pub const fn is_noncharacter(self) -> bool

Returns true if the given Unicode scalar code is a noncharacter.

Note that this also checks against reserved, potential non-characters.

Source

pub const fn is_combining(self) -> bool

Returns true for all Unicode combining characters.

Includes musical notation, historic scripts, and obscure diacritics. Comprehensive but slightly slower than is_combining_common.

Source

pub const fn is_combining_common(self) -> bool

Returns true for common combining marks used in modern text.

Covers Latin, Greek, and most European language diacritics. Fast and suitable for 95% of use cases.

Source

pub const fn is_control(self) -> bool

Returns true for all Unicode control characters.

Source

pub const fn is_control_common(self) -> bool

Returns true for common Unicode control characters.

Just ASCII, zero-width spaces, bidi formatting, word joiners and invisible operators.

Source

pub const fn is_fullwidth(self) -> bool

Returns true for all Unicode fullwidth characters.

Source

pub const fn is_fullwidth_common(self) -> bool

Returns true for common fullwidth characters (ASCII variants, basic CJK)

Source

pub const fn as_ascii(self) -> &'static str โ“˜

Returns the ASCII &'static str representation of the value, or "" if non-ASCII.

Source

pub const fn as_ascii_unchecked(self) -> &'static str โ“˜

Returns the ASCII &'static str representation of the value, or panics if non-ASCII.

ยงPanics

Panics if the character is not ASCII.

Source

pub const fn to_utf8_bytes(self) -> Option<[u8; 4]> โ“˜

Converts the Unicode scalar value to a UTF-8 encoded byte sequence array.

Returns None if the value is not a valid Unicode scalar. The result is always a [u8; 4] array, with unused bytes set to 0.

See also char::encode_utf8.

Source

pub const fn to_utf8_bytes_unchecked(self) -> [u8; 4]

Converts the Unicode scalar value to a UTF-8 encoded byte sequence without validation.

Assumes the value is a valid Unicode scalar. Always returns a [u8; 4] array, with unused bytes set to 0.

See also Char::to_utf8_bytes for a checked version.

Source

pub const fn write_utf8_to_unchecked(self, buf: &mut [u8]) -> usize

Writes this Unicode scalar as UTF-8 into buf without validation.

Returns the number of bytes written.

A buffer of 4 bytes is always large enough for any Unicode scalar.

ยงPanics

Panics if buf.len() < self.0.len_utf8().

Source

pub const fn random_next(rng: &mut Pcg32) -> u32

Returns a Unicode scalar selected from the next output of rng.

Source

pub const fn random_from_seed(seed: u64) -> u32

Returns a Unicode scalar deterministically selected from seed.

Sourceยง

impl Char<u8>

ยงMethods over u8.

Source

pub const fn len_utf8(self) -> Option<usize> โ“˜

Returns the expected UTF-8 byte length based on the given first byte, or None if invalid.

LUT based (256-byte array).

Source

pub const fn len_utf8_unchecked(self) -> usize

Returns the expected UTF-8 byte length based on the given first byte, or 0 if invalid.

LUT based (256-byte array).

Source

pub const fn len_utf8_match(self) -> Option<usize> โ“˜

Returns the expected UTF-8 byte length based on the given first byte, or None if invalid.

Match based, for when memory accesses are more expensive than branches.

Source

pub const fn len_utf8_match_naive(self) -> usize

Returns the expected UTF-8 byte length based on the given first byte.

Match based, for when memory accesses are more expensive than branches.

This function does not validate UTF-8 but determines how many bytes a valid sequence should occupy based on the leading byte.

ยงCaveat
  • If used on malformed UTF-8, it may suggest a length longer than the actual valid sequence.
  • Always use in conjunction with proper UTF-8 validation if handling untrusted input.
Source

pub const fn is_utf8_boundary(self) -> bool

Returns true if this byte is a valid starting point for a UTF-8 sequence.

This checks if the byte is not a UTF-8 continuation byte (i.e., itโ€™s either an ASCII character or a valid leading byte of a multi-byte sequence).

Source

pub const fn is_utf8_continuation(self) -> bool

Returns true if this byte is a UTF-8 continuation byte.

Continuation bytes have the bit pattern 10xxxxxx.

Source

pub const fn as_char(self) -> char

Returns the current byte as a char.

See char::from(u8).

Sourceยง

impl Char<&[u8]>

ยงMethods over u8 slice.

Source

pub const fn to_char(self, index: usize) -> Option<(char, usize)> โ“˜

Decodes a UTF-8 scalar at index.

Returns Some((char, len)) if the input is a valid UTF-8 sequence and the decoded value is a valid Unicode scalar.

Returns None if:

  • The index is out of bounds.
  • The bytes do not form a valid UTF-8 sequence.
  • The decoded value is not a valid Unicode scalar.

This is implemented via Char::to_scalar().

ยงExamples
// Valid UTF-8 sequence
let result = Char(b"\xE2\x82\xAC").to_char(0); // โ‚ฌ
assert_eq!(result, Some(('โ‚ฌ', 3)));

// Invalid continuation bytes
let invalid_continuation = Char(b"\xE2\x41\xAC").to_char(0);
assert_eq!(invalid_continuation, None);

// Surrogate code point
let surrogate = Char(b"\xED\xA0\x80").to_char(0); // U+D800
assert_eq!(surrogate, None);

// Out of bounds index
let out_of_bounds = Char(b"hello").to_char(10);
assert_eq!(out_of_bounds, None);

// Incomplete sequence
let incomplete = Char(b"\xE2\x82").to_char(0); // Missing third byte
assert_eq!(incomplete, None);
ยงFeatures

Uses the unsafe_str feature to skip duplicated validation checks.

Source

pub const fn to_char_lenient(self, index: usize) -> (char, usize) โ“˜

Decodes a UTF-8 scalar leniently at index, validating only the final Unicode scalar.

This method is forgiving of UTF-8 encoding errors but ensures the result is a valid Unicode scalar value.

  • Does not validate UTF-8 continuation bytes (may decode malformed sequences).
  • If the leading byte is invalid it returns the replacement character (๏ฟฝ).

This is implemented via Char::to_scalar_unchecked().

ยงPanics

Panics if the decoded value is not a valid Unicode scalar value, or if the index is out of bounds.

ยงExamples
// Valid UTF-8 sequence
let result = Char(b"\xE2\x82\xAC").to_char_lenient(0); // โ‚ฌ
assert_eq!(result, ('โ‚ฌ', 3));

// Invalid UTF-8 but decodes to valid scalar - behavior depends on input
// This may return unexpected characters rather than panicking
let result = Char(b"\xE2\x41\xAC").to_char_lenient(0);
assert_eq!(result, ('\u{206c}', 3));

// Surrogate code point - will panic
// let result = Char(b"\xED\xA0\x80").to_char_lenient(0); // PANIC: U+D800 is invalid

// Out of bounds index - will panic
// let result = Char(b"hello").to_char_lenient(10); // PANIC: index out of bounds
Source

pub const unsafe fn to_char_unchecked(self, index: usize) -> (char, usize) โ“˜

Available on crate feature unsafe_str and non-crate feature safe_text only.

Decodes a UTF-8 scalar at index without any validation.

If the leading byte is invalid it returns the replacement character (๏ฟฝ).

This is implemented via Char::to_scalar_unchecked.

ยงSafety

The caller must ensure that:

  • index is within bounds of bytes
  • bytes[index..] contains a valid UTF-8 sequence
  • The decoded value is a valid Unicode scalar.

Violating these conditions may lead to undefined behavior.

Source

pub const fn to_scalar(self, index: usize) -> Option<(u32, usize)> โ“˜

Decodes a UTF-8 scalar from the given byte slice, starting at index.

Returns (scalar, len), where scalar is the decoded Unicode scalar, and len is the number of bytes consumed.

Returns None if:

  • The index is out of bounds.
  • The bytes do not form a valid UTF-8 sequence.
  • The decoded value is not a valid Unicode scalar.
ยงExamples
assert_eq!(Char("ฤฆ".as_bytes()).to_scalar(0), Some((u32::from('ฤฆ'), 2)));

let invalid = b"\x80"; // Invalid leading byte
assert_eq!(Char(invalid).to_scalar(0), None);
Source

pub const fn to_scalar_unchecked(self, index: usize) -> (u32, usize) โ“˜

Decodes a UTF-8 scalar from the given byte slice, starting at index, without validation.

Returns (scalar, len), where scalar is the decoded Unicode scalar, and len is the number of bytes consumed.

It assumes bytes[index..] contains a valid UTF-8 sequence, and it doesnโ€™t validate the resulting Unicode scalar.

If the leading byte is invalid it returns the replacement character (๏ฟฝ).

ยงPanics

It will panic if the index is out of bounds.

Source

pub const fn has_overlong_encoding(self, index: usize, len: usize) -> bool

Returns true if the UTF-8 sequence starting at index is overlong encoded.

This method only checks for overlong encodings, but not other UTF-8 validity rules. It does not verify continuation byte patterns nor invalid scalar values.

Overlong encodings use more bytes than necessary to represent a character, which is invalid in well-formed UTF-8.

ยงExamples
assert!(Char(b"\xE0\x80\x80").has_overlong_encoding(0, 3)); // overlong encoding
assert!(!Char(b"\xE0\xA0\x80").has_overlong_encoding(0, 3)); // valid 3-byte sequence
Source

pub const fn has_valid_continuation(self, index: usize, len: usize) -> bool

Verifies that the continuation bytes following a UTF-8 leading byte are properly formatted.

Each continuation byte must match the pattern 10xxxxxx (i.e., have the high bits 0b10). This ensures the byte sequence follows proper UTF-8 encoding rules.

This method only verifies correct syntax, but not correct semantics. It does not check for overlong encodings nor invalid scalar values.

ยงExamples
assert!(Char(b"\xE2\x82\xAC").has_valid_continuation(0, 3)); // euro sign โ‚ฌ
assert!(!Char(b"\xE2\x41\xAC").has_valid_continuation(0, 3)); // second byte is ASCII 'A'
assert!(!Char(b"\xC2").has_valid_continuation(0, 2)); // incomplete sequence
Source

pub const fn is_utf8_boundary(self, index: usize) -> bool

Returns true if the byte at index is a valid starting point for a UTF-8 sequence.

This checks if the byte is not a UTF-8 continuation byte (i.e., itโ€™s either an ASCII character or a valid leading byte of a multi-byte sequence).

Useful for safely starting UTF-8 decoding from an arbitrary position in a byte slice.

Source

pub const fn ceil_utf8_boundary(self, index: usize) -> usize

Returns the smallest UTF-8 boundary >= index.

Source

pub const fn floor_utf8_boundary(self, index: usize) -> usize

Returns the greatest UTF-8 boundary <= index.

If index > self.len(), starts from self.len().

This only checks boundary shape, not full UTF-8 validity. It is intended for already-valid UTF-8 byte slices.

Sourceยง

impl<const N: usize> Char<&[u8; N]>

Method wrappers over a byte array reference.

Source

pub const fn to_char(self, index: usize) -> Option<(char, usize)> โ“˜

A wrapper over to_char().

Source

pub const fn to_char_lenient(self, index: usize) -> (char, usize) โ“˜

A wrapper over to_char_lenient().

Source

pub const unsafe fn to_char_unchecked(self, index: usize) -> (char, usize) โ“˜

Available on crate feature unsafe_str and non-crate feature safe_text only.

A wrapper over to_char_unchecked().

ยงSafety

Same requirements as the wrapped method.

Source

pub const fn to_scalar(self, index: usize) -> Option<(u32, usize)> โ“˜

A wrapper over to_scalar().

Source

pub const fn to_scalar_unchecked(self, index: usize) -> (u32, usize) โ“˜

A wrapper over to_scalar_unchecked().

Source

pub const fn has_overlong_encoding(self, index: usize, len: usize) -> bool

A wrapper over has_overlong_encoding().

Source

pub const fn has_valid_continuation(self, index: usize, len: usize) -> bool

A wrapper over has_valid_continuation().

Source

pub const fn is_utf8_boundary(self, index: usize) -> bool

A wrapper over is_utf8_boundary().

Source

pub const fn ceil_utf8_boundary(self, index: usize) -> usize

A wrapper over ceil_utf8_boundary().

Source

pub const fn floor_utf8_boundary(self, index: usize) -> usize

A wrapper over floor_utf8_boundary().

Trait Implementationsยง

Sourceยง

impl<T: Clone> Clone for Char<T>

Sourceยง

fn clone(&self) -> Char<T>

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<T: Copy> Copy for Char<T>

Sourceยง

impl<T: Debug> Debug for Char<T>

Sourceยง

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

Formats the value using the given formatter. Read more

Auto Trait Implementationsยง

ยง

impl<T> Freeze for Char<T>
where T: Freeze,

ยง

impl<T> RefUnwindSafe for Char<T>
where T: RefUnwindSafe,

ยง

impl<T> Send for Char<T>
where T: Send,

ยง

impl<T> Sync for Char<T>
where T: Sync,

ยง

impl<T> Unpin for Char<T>
where T: Unpin,

ยง

impl<T> UnsafeUnpin for Char<T>
where T: UnsafeUnpin,

ยง

impl<T> UnwindSafe for Char<T>
where T: UnwindSafe,

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

Sourceยง

fn type_id() -> TypeId

Returns the TypeId of Self. Read more
Sourceยง

fn type_of(&self) -> TypeId

Returns the TypeId of self. Read more
Sourceยง

fn type_name(&self) -> &'static str โ“˜

Returns the type name of self. Read more
Sourceยง

fn type_is<T: 'static>(&self) -> bool

Returns true if Self is of type T. Read more
Sourceยง

fn type_hash(&self) -> u64

Returns a deterministic hash of the TypeId of Self.
Sourceยง

fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64

Returns a deterministic hash of the TypeId of Self using a custom hasher.
Sourceยง

fn as_any_ref(&self) -> &dyn Any
where Self: Sized,

Upcasts &self as &dyn Any. Read more
Sourceยง

fn as_any_mut(&mut self) -> &mut dyn Any
where Self: Sized,

Upcasts &mut self as &mut dyn Any. Read more
Sourceยง

fn as_any_box(self: Box<Self>) -> Box<dyn Any>
where Self: Sized,

Available on crate feature alloc only.
Upcasts Box<self> as Box<dyn Any>. Read more
Sourceยง

fn downcast_ref<T: 'static>(&self) -> Option<&T> โ“˜

Available on crate feature unsafe_layout and non-crate feature safe_code only.
Returns some shared reference to the inner value if it is of type T. Read more
Sourceยง

fn downcast_mut<T: 'static>(&mut self) -> Option<&mut T> โ“˜

Available on crate feature unsafe_layout and non-crate feature safe_code only.
Returns some exclusive reference to the inner value if it is of type T. 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> ByteSized for T

Sourceยง

const BYTE_ALIGN: usize = _

The alignment of this type in bytes.
Sourceยง

const BYTE_SIZE: usize = _

The size of this type in bytes.
Sourceยง

fn byte_align(&self) -> usize

Returns the alignment of this type in bytes.
Sourceยง

fn byte_size(&self) -> usize

Returns the size of this type in bytes. Read more
Sourceยง

fn ptr_size_ratio(&self) -> [usize; 2]

Returns the size ratio between Ptr::BYTES and BYTE_SIZE. 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> Hook for T

Sourceยง

fn hook<F>(self, f: F) -> Self
where F: FnOnce(&mut Self),

Hooks a mutation step into the value and returns it. Read more
Sourceยง

fn tap<F>(self, f: F) -> Self
where F: FnOnce(&Self),

Taps into the value for observation and returns it unchanged. Read more
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> MemExt for T
where T: ?Sized,

Sourceยง

const NEEDS_DROP: bool = _

Know whether dropping values of this type matters, in compile-time.
Sourceยง

fn mem_align_of<T>() -> usize

Returns the minimum alignment of the type in bytes. Read more
Sourceยง

fn mem_align_of_val(&self) -> usize

Returns the alignment of the pointed-to value in bytes. Read more
Sourceยง

fn mem_size_of<T>() -> usize

Returns the size of a type in bytes. Read more
Sourceยง

fn mem_size_of_val(&self) -> usize

Returns the size of the pointed-to value in bytes. Read more
Sourceยง

fn mem_copy(&self) -> Self
where Self: Copy,

Bitwise-copies a value. Read more
Sourceยง

fn mem_needs_drop(&self) -> bool

Returns true if dropping values of this type matters. Read more
Sourceยง

fn mem_drop(self)
where Self: Sized,

Drops self by running its destructor. Read more
Sourceยง

fn mem_forget(self)
where Self: Sized,

Forgets about self without running its destructor. Read more
Sourceยง

fn mem_replace(&mut self, other: Self) -> Self
where Self: Sized,

Replaces self with other, returning the previous value of self. Read more
Sourceยง

fn mem_take(&mut self) -> Self
where Self: Default,

Replaces self with its default value, returning the previous value of self. Read more
Sourceยง

fn mem_swap(&mut self, other: &mut Self)
where Self: Sized,

Swaps the value of self and other without deinitializing either one. Read more
Sourceยง

unsafe fn mem_zeroed<T>() -> T

Available on crate feature unsafe_layout only.
Returns the value of type T represented by the all-zero byte-pattern. Read more
Sourceยง

unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst

Available on crate feature unsafe_layout only.
Returns the value of type T represented by the all-zero byte-pattern. Read more
Sourceยง

fn mem_as_bytes(&self) -> &[u8] โ“˜
where Self: Sync + Unpin,

Available on crate feature unsafe_slice only.
View a Sync + Unpin self as &[u8]. Read more
Sourceยง

fn mem_as_bytes_mut(&mut self) -> &mut [u8] โ“˜
where Self: Sync + Unpin,

Available on crate feature unsafe_slice only.
View a Sync + Unpin self as &mut [u8]. Read more
Sourceยง

impl<T, R> Morph<R> for T
where T: ?Sized,

Sourceยง

fn morph<F>(self, f: F) -> R
where F: FnOnce(Self) -> R, Self: Sized,

Morphs the value into a new one and returns it. Read more
Sourceยง

fn morph_ref<F>(&self, f: F) -> R
where F: FnOnce(&Self) -> R,

Morphs the value by shared reference and returns the result. Read more
Sourceยง

fn morph_mut<F>(&mut self, f: F) -> R
where F: FnOnce(&mut Self) -> R,

Morphs the value by exclusive reference and returns the result. Read more
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 = 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.