Skip to content

Commit 278e335

Browse files
committed
Make position helper return Result
1 parent 2f2c82a commit 278e335

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

core/document/src/layers/folder.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,20 @@ impl Folder {
5959
}
6060

6161
pub fn remove_layer(&mut self, id: LayerId) -> Result<(), DocumentError> {
62-
let pos = self.position_of_layer(id).ok_or(DocumentError::LayerNotFound)?;
62+
let pos = self.position_of_layer(id)?;
6363
self.layers.remove(pos);
6464
self.layer_ids.remove(pos);
6565
Ok(())
6666
}
6767

6868
pub fn reorder_layers(&mut self, source_ids: Vec<LayerId>, target_id: LayerId) -> Result<(), DocumentError> {
69-
let source_pos = self.position_of_layer(source_ids[0]).ok_or(DocumentError::LayerNotFound)?;
69+
let source_pos = self.position_of_layer(source_ids[0])?;
7070
let source_pos_end = source_pos + source_ids.len() - 1;
71-
let target_pos = self.position_of_layer(target_id).ok_or(DocumentError::LayerNotFound)?;
71+
let target_pos = self.position_of_layer(target_id)?;
7272

7373
let mut last_pos = source_pos;
7474
for layer_id in &source_ids[1..source_ids.len()] {
75-
let layer_pos = self.position_of_layer(*layer_id).ok_or(DocumentError::LayerNotFound)?;
75+
let layer_pos = self.position_of_layer(*layer_id)?;
7676
if (layer_pos as i32 - last_pos as i32).abs() > 1 {
7777
// Selection is not contiguous
7878
return Err(DocumentError::NonReorderableSelection);
@@ -141,17 +141,17 @@ impl Folder {
141141
}
142142

143143
pub fn layer(&self, id: LayerId) -> Option<&Layer> {
144-
let pos = self.position_of_layer(id)?;
144+
let pos = self.position_of_layer(id).ok()?;
145145
Some(&self.layers[pos])
146146
}
147147

148148
pub fn layer_mut(&mut self, id: LayerId) -> Option<&mut Layer> {
149-
let pos = self.position_of_layer(id)?;
149+
let pos = self.position_of_layer(id).ok()?;
150150
Some(&mut self.layers[pos])
151151
}
152152

153-
pub fn position_of_layer(&self, layer_id: LayerId) -> Option<usize> {
154-
self.layer_ids.iter().position(|x| *x == layer_id)
153+
pub fn position_of_layer(&self, layer_id: LayerId) -> Result<usize, DocumentError> {
154+
self.layer_ids.iter().position(|x| *x == layer_id).ok_or(DocumentError::LayerNotFound)
155155
}
156156

157157
pub fn folder(&self, id: LayerId) -> Option<&Folder> {

0 commit comments

Comments
 (0)