Skip to content

Commit 5e8a693

Browse files
committed
Simplify source_layer_ids computation
1 parent 5e13027 commit 5e8a693

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

core/document/src/document.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,10 @@ impl Document {
229229
pub fn reorder_layers(&mut self, source_paths: &[Vec<LayerId>], target_path: &[LayerId]) -> Result<(), DocumentError> {
230230
// TODO: Detect when moving between folders and handle properly
231231

232-
let mut source_layer_ids = Vec::with_capacity(source_paths.len());
233-
for path in source_paths {
234-
let result = path.last();
235-
match result {
236-
Some(result) => source_layer_ids.push(*result),
237-
None => return Err(DocumentError::LayerNotFound),
238-
}
239-
}
232+
let source_layer_ids = source_paths
233+
.iter()
234+
.map(|x| x.last().cloned().ok_or(DocumentError::LayerNotFound))
235+
.collect::<Result<Vec<LayerId>, DocumentError>>()?;
240236

241237
self.root.as_folder_mut()?.reorder_layers(source_layer_ids, *target_path.last().ok_or(DocumentError::LayerNotFound)?)?;
242238

0 commit comments

Comments
 (0)