Skip to main content

Cell

Struct Cell 

Source
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>

Source

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 the CellType trait.
§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());
Source

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 the CellType trait.
  • 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());
Source

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());
Source

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());
Source

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());
Source

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§

Source§

impl<T: Clone + CellType> Clone for Cell<T>

Source§

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

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<T: Debug + CellType> Debug for Cell<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 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> 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.