pub struct Cell<T: CellType> { /* private fields */ }Expand description
A struct to hold a cell position and value.
A Cell is a fundamental worksheet type that is used to create a Range.
It contains a position and a value.
§Examples
An example of creating a range of Cells and iterating over them.
use calamine::{Cell, Data, Range};
let cells = vec![
Cell::new((1, 1), Data::Int(1)),
Cell::new((1, 2), Data::Int(2)),
Cell::new((3, 1), Data::Int(3)),
];
// Create a Range from the cells.
let range = Range::from_sparse(cells);
// Iterate over the cells in the range.
for (row, col, data) in range.cells() {
println!("({row}, {col}): {data}");
}
Output:
(0, 0): 1
(0, 1): 2
(1, 0):
(1, 1):
(2, 0): 3
(2, 1):Implementations§
Source§impl<T: CellType> Cell<T>
impl<T: CellType> Cell<T>
Sourcepub fn new(position: (u32, u32), value: T) -> Cell<T>
pub fn new(position: (u32, u32), value: T) -> Cell<T>
Creates a new Cell instance.
§Parameters
position: A tuple representing the cell’s position in the form of(row, column).value: The value of the cell, which must implement theCellTypetrait.
§Examples
An example of creating a new Cell instance.
use calamine::{Cell, Data};
let cell = Cell::new((1, 2), Data::Int(42));
assert_eq!(&Data::Int(42), cell.get_value());Sourcepub fn with_style(position: (u32, u32), value: T, style: Style) -> Cell<T>
pub fn with_style(position: (u32, u32), value: T, style: Style) -> Cell<T>
Creates a new Cell instance with style information.
§Parameters
position: A tuple representing the cell’s position in the form of(row, column).value: The value of the cell, which must implement theCellTypetrait.style: The style information for the cell.
§Examples
An example of creating a new Cell instance with style.
use calamine::{Cell, Data, Style, Font, FontWeight};
let style = Style::new().with_font(Font::new().with_weight(FontWeight::Bold));
let cell = Cell::with_style((1, 2), Data::Int(42), style);
assert_eq!(&Data::Int(42), cell.get_value());
assert!(cell.get_style().is_some());Sourcepub fn get_position(&self) -> (u32, u32)
pub fn get_position(&self) -> (u32, u32)
Gets Cell position.
§Examples
An example of getting a Cell position (row, column).
use calamine::{Cell, Data};
let cell = Cell::new((1, 2), Data::Int(42));
assert_eq!((1, 2), cell.get_position());Sourcepub fn get_value(&self) -> &T
pub fn get_value(&self) -> &T
Gets Cell value.
§Examples
An example of getting a Cell value.
use calamine::{Cell, Data};
let cell = Cell::new((1, 2), Data::Int(42));
assert_eq!(&Data::Int(42), cell.get_value());Sourcepub fn get_style(&self) -> Option<&Style>
pub fn get_style(&self) -> Option<&Style>
Gets Cell style.
§Examples
An example of getting a Cell style.
use calamine::{Cell, Data, Style, Font, FontWeight};
let style = Style::new().with_font(Font::new().with_weight(FontWeight::Bold));
let cell = Cell::with_style((1, 2), Data::Int(42), style);
assert!(cell.get_style().is_some());Sourcepub fn has_style(&self) -> bool
pub fn has_style(&self) -> bool
Checks if the cell has any style information.
§Examples
An example of checking if a Cell has style.
use calamine::{Cell, Data, Style, Font, FontWeight};
let cell = Cell::new((1, 2), Data::Int(42));
assert!(!cell.has_style());
let style = Style::new().with_font(Font::new().with_weight(FontWeight::Bold));
let cell_with_style = Cell::with_style((1, 2), Data::Int(42), style);
assert!(cell_with_style.has_style());Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Cell<T>where
T: Freeze,
impl<T> RefUnwindSafe for Cell<T>where
T: RefUnwindSafe,
impl<T> Send for Cell<T>where
T: Send,
impl<T> Sync for Cell<T>where
T: Sync,
impl<T> Unpin for Cell<T>where
T: Unpin,
impl<T> UnsafeUnpin for Cell<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Cell<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more