Struct calamine::Range
[−]
[src]
pub struct Range { /* fields omitted */ }
A struct which represents a squared selection of cells
Methods
impl Range
[src]
fn new(start: (u32, u32), end: (u32, u32)) -> Range
Creates a new Range
When possible, prefer the more efficient Range::from_sparse
fn from_sparse(cells: Vec<Cell>) -> Range
Creates a Range
from a coo sparse vector of Cell
s.
Coordinate list (COO) is the natural way cells are stored in excel files Inner size is defined only by non empty.
cells: Vec
of non empty Cell
s, sorted by row
Panics
panics when a Cell
row is lower than the first Cell
row or
bigger than the last Cell
row.
Examples
use calamine::{Range, DataType, Cell}; let v = vec![Cell::new((1, 200), DataType::Float(1.)), Cell::new((55, 2), DataType::String("a".to_string()))]; let range = Range::from_sparse(v); assert_eq!(range.get_size(), (55, 199));
fn start(&self) -> (u32, u32)
Get top left cell position (row, column)
fn end(&self) -> (u32, u32)
Get bottom right cell position (row, column)
fn width(&self) -> usize
Get column width
fn height(&self) -> usize
Get column width
fn get_size(&self) -> (usize, usize)
Get size
fn is_empty(&self) -> bool
Is range empty
fn set_value(&mut self, pos: (u32, u32), value: DataType) -> Result<()>
Set inner value
Will try to resize inner structure if the value is out of bounds.
Try to avoid this method as much as possible and prefer initializing
the Range
with from_sparce
constructor.
Examples
use calamine::{Range, DataType}; let mut range = Range::new((0, 0), (5, 2)); assert_eq!(range.get_value((2, 1)), &DataType::Empty); range.set_value((2, 1), DataType::Float(1.0)) .expect("Cannot set value at position (2, 1)"); assert_eq!(range.get_value((2, 1)), &DataType::Float(1.0));
fn get_value(&self, pos: (u32, u32)) -> &DataType
Get cell value
Panics if indexes are out of range bounds
fn rows(&self) -> Rows
Get an iterator over inner rows
Examples
use calamine::Range; let range = Range::new((0, 0), (5, 2)); // with rows item row: &[DataType] assert_eq!(range.rows().map(|r| r.len()).sum::<usize>(), 18);
fn used_cells(&self) -> UsedCells
Get an iterator over used cells only
This can be much faster than iterating rows as Range
is saved as a sparce matrix
Trait Implementations
impl Debug for Range
[src]
impl Default for Range
[src]
impl Clone for Range
[src]
fn clone(&self) -> Range
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more