use compact_str::CompactString;
use crate::style::Style;
const _: () = assert!(
std::mem::size_of::<Cell>() <= 64,
"Cell exceeds one cache line (64 B). If the size increase is intentional, update this bound and document why."
);
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Cell {
pub symbol: CompactString,
pub style: Style,
pub hyperlink: Option<CompactString>,
}
impl Default for Cell {
fn default() -> Self {
Self {
symbol: CompactString::const_new(" "),
style: Style::new(),
hyperlink: None,
}
}
}
impl Cell {
pub fn set_symbol(&mut self, s: &str) -> &mut Self {
self.symbol.clear();
self.symbol.push_str(s);
self
}
pub fn set_char(&mut self, ch: char) -> &mut Self {
self.symbol.clear();
self.symbol.push(ch);
self
}
pub fn set_style(&mut self, style: Style) -> &mut Self {
self.style = style;
self
}
pub fn reset(&mut self) {
self.symbol.clear();
self.symbol.push(' ');
self.style = Style::new();
self.hyperlink = None;
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn cell_size_within_cache_line() {
let size = std::mem::size_of::<Cell>();
assert!(
size <= 64,
"Cell size = {size}B; exceeds 64B cache-line budget. If intentional, update the const-assert and this test together."
);
}
}