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 0CONTINUATION(0x1): Placeholder for wide character continuation
Implementations§
Source§impl CellContent
impl CellContent
Sourcepub const CONTINUATION: Self
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).
Sourcepub const fn from_char(c: char) -> Self
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.
Sourcepub const fn from_grapheme(id: GraphemeId) -> Self
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.
Sourcepub const fn is_grapheme(self) -> bool
pub const fn is_grapheme(self) -> bool
Check if this content is a grapheme reference (vs direct char).
Sourcepub const fn is_continuation(self) -> bool
pub const fn is_continuation(self) -> bool
Check if this is a continuation cell (part of a wide character).
Sourcepub fn as_char(self) -> Option<char>
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.
Sourcepub const fn grapheme_id(self) -> Option<GraphemeId>
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.
Sourcepub const fn width_hint(self) -> usize
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.
Trait Implementations§
Source§impl Clone for CellContent
impl Clone for CellContent
Source§fn clone(&self) -> CellContent
fn clone(&self) -> CellContent
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more