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]
fn new(start: (u32, u32), end: (u32, u32)) -> Range<T>
[src]
Creates a new Range
When possible, prefer the more efficient Range::from_sparse
fn start(&self) -> (u32, u32)
[src]
Get top left cell position (row, column)
fn end(&self) -> (u32, u32)
[src]
Get bottom right cell position (row, column)
fn width(&self) -> usize
[src]
Get column width
fn height(&self) -> usize
[src]
Get column width
fn get_size(&self) -> (usize, usize)
[src]
Get size
fn is_empty(&self) -> bool
[src]
Is range empty
fn set_value(&mut self, absolute_position: (u32, u32), value: T) -> Result<()>
[src]
Set inner value from absolute position
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_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, absolute_position: (u32, u32)) -> &T
[src]
Get cell value from absolute position
For relative positions, use Index trait
Panics if indexes are out of range bounds
fn rows(&self) -> Rows<T>
[src]
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);
fn used_cells(&self) -> UsedCells<T>
[src]
Get an iterator over used cells only
fn deserialize<'a, D>(&'a self) -> Result<RangeDeserializer<'a, T, D>> where
T: ToCellDeserializer<'a>,
D: DeserializeOwned,
[src]
T: ToCellDeserializer<'a>,
D: DeserializeOwned,
Build a RangeDeserializer
from this configuration.
Example
fn example() -> Result<()> { let path = format!("{}/tests/tempurature.xlsx", env!("CARGO_MANIFEST_DIR")); let mut workbook = Sheets::open(path)?; let mut sheet = workbook.worksheet_range("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: Default + CellType> Default for Range<T>
[src]
impl<T: Clone + CellType> Clone for Range<T>
[src]
fn clone(&self) -> Range<T>
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<T: CellType> Index<usize> for Range<T>
[src]
type Output = [T]
The returned type after indexing.
fn index(&self, index: usize) -> &[T]
[src]
Performs the indexing (container[index]
) operation.
impl<T: CellType> Index<(usize, usize)> for Range<T>
[src]
type Output = T
The returned type after indexing.
fn index(&self, index: (usize, usize)) -> &T
[src]
Performs the indexing (container[index]
) operation.
impl<T: CellType> IndexMut<usize> for Range<T>
[src]
fn index_mut(&mut self, index: usize) -> &mut [T]
[src]
Performs the mutable indexing (container[index]
) operation.