Skip to main content

CellContent

Struct CellContent 

Source
pub struct CellContent(/* private fields */);
Expand description

Cell content: either a direct Unicode char or a reference to a grapheme cluster.

§Encoding Scheme (4 bytes)

Bit 31 (type discriminator):
  0: Direct char (bits 0-20 contain Unicode scalar value, max U+10FFFF)
  1: GraphemeId reference (bits 0-30 contain slot + width)

This allows:

  • 99% of cells (ASCII/BMP) to be stored without heap allocation
  • Complex graphemes (emoji, ZWJ sequences) stored in pool

§Special Values

  • EMPTY (0x0): Empty cell, width 0
  • CONTINUATION (0x1): Placeholder for wide character continuation

Implementations§

Source§

impl CellContent

Source

pub const EMPTY: Self

Empty cell content (no character).

Source

pub const CONTINUATION: Self

Continuation marker for wide characters.

When a character has display width > 1, subsequent cells are filled with this marker to indicate they are part of the previous character.

Value is 0x7FFF_FFFF (max i32), which is outside valid Unicode scalar range (0..0x10FFFF) but fits in 31 bits (Direct Char mode).

Source

pub const fn from_char(c: char) -> Self

Create content from a single Unicode character.

For characters with display width > 1, subsequent cells should be filled with CONTINUATION.

Source

pub const fn from_grapheme(id: GraphemeId) -> Self

Create content from a grapheme ID (for multi-codepoint clusters).

The grapheme ID references an entry in the GraphemePool.

Source

pub const fn is_grapheme(self) -> bool

Check if this content is a grapheme reference (vs direct char).

Source

pub const fn is_continuation(self) -> bool

Check if this is a continuation cell (part of a wide character).

Source

pub const fn is_empty(self) -> bool

Check if this cell is empty.

Source

pub const fn is_default(self) -> bool

Check if this content is the default value.

This is equivalent to is_empty() and primarily exists for readability in tests.

Source

pub fn as_char(self) -> Option<char>

Extract the character if this is a direct char (not a grapheme).

Returns None if this is empty, continuation, or a grapheme reference.

Source

pub const fn grapheme_id(self) -> Option<GraphemeId>

Extract the grapheme ID if this is a grapheme reference.

Returns None if this is a direct char.

Source

pub const fn width_hint(self) -> usize

Get the display width of this content.

  • Empty: 0
  • Continuation: 0
  • Grapheme: width embedded in GraphemeId
  • Char: requires external width lookup (returns 1 as default for ASCII)

Note: For accurate char width, use the unicode-display-width-based helpers in this crate. This method provides a fast path for known cases.

Source

pub fn width(self) -> usize

Get the display width of this content with Unicode width semantics.

This is the accurate (but slower) width computation for direct chars.

Source

pub const fn raw(self) -> u32

Raw u32 value.

Trait Implementations§

Source§

impl Clone for CellContent

Source§

fn clone(&self) -> CellContent

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CellContent

Source§

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

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

impl Default for CellContent

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Hash for CellContent

Source§

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

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 PartialEq for CellContent

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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.
Source§

impl Copy for CellContent

Source§

impl Eq for CellContent

Source§

impl StructuralPartialEq for CellContent

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