summaryrefslogtreecommitdiff
path: root/src/sheet/cell.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/sheet/cell.rs')
-rw-r--r--src/sheet/cell.rs38
1 files changed, 10 insertions, 28 deletions
diff --git a/src/sheet/cell.rs b/src/sheet/cell.rs
index b46b7d4..d723732 100644
--- a/src/sheet/cell.rs
+++ b/src/sheet/cell.rs
@@ -98,14 +98,14 @@ impl CellRef {
sheet_id,
row,
column,
- value: cell
+ value: cell,
}
}
pub fn fetch_new(sheet_id: SheetId, row: usize, column: usize) -> Option<Self> {
Register::get(sheet_id)
.map(|sheet| {
- sheet.read().unwrap().get_cell(row, column).map(|cell| Self {
+ sheet.get_cell(row, column).map(|cell| Self {
sheet_id,
row,
column,
@@ -120,12 +120,10 @@ impl CellRef {
}
pub fn set_value(&mut self, cell: Cell) {
- self.value = cell.clone();
- Register::get(self.sheet_id)
- .unwrap()
- .write()
- .unwrap()
- .set_cell(self.row, self.column, cell);
+ if let Some(sheet) = Register::get(self.sheet_id) {
+ self.value = cell.clone();
+ sheet.set_cell(self.row, self.column, cell);
+ }
}
pub fn left(&self) -> Option<Self> {
@@ -157,16 +155,8 @@ impl CellRef {
}
pub fn end(&self) -> Option<Self> {
- Self::fetch_new(
- self.sheet_id,
- self.row,
- Register::get(self.sheet_id)
- .unwrap()
- .read()
- .unwrap()
- .width()
- - 1,
- )
+ Register::get(self.sheet_id)
+ .map(|sheet| Self::fetch_new(self.sheet_id, self.row, sheet.width() - 1))?
}
pub fn top(&self) -> Option<Self> {
@@ -174,16 +164,8 @@ impl CellRef {
}
pub fn bottom(&self) -> Option<Self> {
- Self::fetch_new(
- self.sheet_id,
- Register::get(self.sheet_id)
- .unwrap()
- .read()
- .unwrap()
- .height()
- - 1,
- self.column,
- )
+ Register::get(self.sheet_id)
+ .map(|sheet| Self::fetch_new(self.sheet_id, sheet.height() - 1, self.column))?
}
}