Struct calamine::Range [−][src]
pub struct Range<T: CellType> { /* fields omitted */ }
A struct which represents a squared selection of cells
Methods
impl<T: CellType> Range<T>
[src]
impl<T: CellType> Range<T>
pub fn new(start: (u32, u32), end: (u32, u32)) -> Range<T>
[src]
pub fn new(start: (u32, u32), end: (u32, u32)) -> Range<T>
Creates a new non-empty Range
When possible, prefer the more efficient Range::from_sparse
Panics
Panics if start.0 > end.0 or start.1 > end.1
pub fn empty() -> Range<T>
[src]
pub fn empty() -> Range<T>
Creates a new empty range
pub fn start(&self) -> Option<(u32, u32)>
[src]
pub fn start(&self) -> Option<(u32, u32)>
Get top left cell position (row, column)
pub fn end(&self) -> Option<(u32, u32)>
[src]
pub fn end(&self) -> Option<(u32, u32)>
Get bottom right cell position (row, column)
pub fn width(&self) -> usize
[src]
pub fn width(&self) -> usize
Get column width
pub fn height(&self) -> usize
[src]
pub fn height(&self) -> usize
Get column width
pub fn get_size(&self) -> (usize, usize)
[src]
pub fn get_size(&self) -> (usize, usize)
Get size in (height, width) format
pub fn is_empty(&self) -> bool
[src]
pub fn is_empty(&self) -> bool
Is range empty
pub fn from_sparse(cells: Vec<Cell<T>>) -> Range<T>
[src]
pub fn from_sparse(cells: Vec<Cell<T>>) -> Range<T>
Creates a Range
from a coo sparse vector of Cell
s.
Coordinate list (COO) is the natural way cells are stored 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.
pub fn set_value(&mut self, absolute_position: (u32, u32), value: T)
[src]
pub fn set_value(&mut self, absolute_position: (u32, u32), value: T)
Set inner value from absolute position
Remarks
Will try to resize inner structure if the value is out of bounds. For relative positions, use Index trait
Try to avoid this method as much as possible and prefer initializing
the Range
with from_sparse
constructor.
Panics
If absolute_position > Cell start
Examples
use calamine::{Range, DataType}; let mut range = Range::new((0, 0), (5, 2)); assert_eq!(range.get_value((2, 1)), Some(&DataType::Empty)); range.set_value((2, 1), DataType::Float(1.0)); assert_eq!(range.get_value((2, 1)), Some(&DataType::Float(1.0)));
pub fn get_value(&self, absolute_position: (u32, u32)) -> Option<&T>
[src]
pub fn get_value(&self, absolute_position: (u32, u32)) -> Option<&T>
Get cell value from absolute position.
If the absolute_position
is out of range, returns None
, else returns the cell value.
The coordinate format is (row, column).
Warnings
For relative positions, use Index trait
Remarks
Absolute position is in sheet referential while relative position is in range referential.
For instance if we consider range C2:H38:
(0, 0)
absolute is "A1" and thus this function returnsNone
(0, 0)
relative is "C2" and is returned by theIndex
trait (i.emy_range[(0, 0)]
)
Examples
use calamine::{Range, DataType}; let range: Range<usize> = Range::new((1, 0), (5, 2)); assert_eq!(range.get_value((0, 0)), None); assert_eq!(range[(0, 0)], 0);
ⓘImportant traits for Rows<'a, T>pub fn rows(&self) -> Rows<T>
[src]
pub fn rows(&self) -> Rows<T>
Get an iterator over inner rows
Examples
use calamine::{Range, DataType}; let range: Range<DataType> = Range::new((0, 0), (5, 2)); // with rows item row: &[DataType] assert_eq!(range.rows().map(|r| r.len()).sum::<usize>(), 18);
ⓘImportant traits for UsedCells<'a, T>pub fn used_cells(&self) -> UsedCells<T>
[src]
pub fn used_cells(&self) -> UsedCells<T>
Get an iterator over used cells only
pub fn deserialize<'a, D>(
&'a self
) -> Result<RangeDeserializer<'a, T, D>, DeError> where
T: ToCellDeserializer<'a>,
D: DeserializeOwned,
[src]
pub fn deserialize<'a, D>(
&'a self
) -> Result<RangeDeserializer<'a, T, D>, DeError> where
T: ToCellDeserializer<'a>,
D: DeserializeOwned,
Build a RangeDeserializer
from this configuration.
Example
fn example() -> Result<(), Error> { let path = format!("{}/tests/tempurature.xlsx", env!("CARGO_MANIFEST_DIR")); let mut workbook: Xlsx<_> = open_workbook(path)?; let mut sheet = workbook.worksheet_range("Sheet1") .ok_or(Error::Msg("Cannot find 'Sheet1'"))??; let mut iter = sheet.deserialize()?; if let Some(result) = iter.next() { let (label, value): (String, f64) = result?; assert_eq!(label, "celcius"); assert_eq!(value, 22.2222); Ok(()) } else { return Err(From::from("expected at least one record but got none")); } }
Trait Implementations
impl<T: Debug + CellType> Debug for Range<T>
[src]
impl<T: Debug + CellType> Debug for Range<T>
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<T: Default + CellType> Default for Range<T>
[src]
impl<T: Default + CellType> Default for Range<T>
impl<T: Clone + CellType> Clone for Range<T>
[src]
impl<T: Clone + CellType> Clone for Range<T>
fn clone(&self) -> Range<T>
[src]
fn clone(&self) -> Range<T>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<T: CellType> Index<usize> for Range<T>
[src]
impl<T: CellType> Index<usize> for Range<T>
type Output = [T]
The returned type after indexing.
fn index(&self, index: usize) -> &[T]
[src]
fn index(&self, index: usize) -> &[T]
Performs the indexing (container[index]
) operation.
impl<T: CellType> Index<(usize, usize)> for Range<T>
[src]
impl<T: CellType> Index<(usize, usize)> for Range<T>
type Output = T
The returned type after indexing.
fn index(&self, index: (usize, usize)) -> &T
[src]
fn index(&self, index: (usize, usize)) -> &T
Performs the indexing (container[index]
) operation.
impl<T: CellType> IndexMut<usize> for Range<T>
[src]
impl<T: CellType> IndexMut<usize> for Range<T>
fn index_mut(&mut self, index: usize) -> &mut [T]
[src]
fn index_mut(&mut self, index: usize) -> &mut [T]
Performs the mutable indexing (container[index]
) operation.
impl<T: CellType> IndexMut<(usize, usize)> for Range<T>
[src]
impl<T: CellType> IndexMut<(usize, usize)> for Range<T>