Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
Resolve rust clippy warnings (#946)
gabrielztk70f9a289a40c
diff --git a/frontend/rust-lib/flowy-grid/src/services/group/configuration.rs b/frontend/rust-lib/flowy-grid/src/services/group/configuration.rsindex ab25cd4307..3fb5cefaa3 100644--- a/frontend/rust-lib/flowy-grid/src/services/group/configuration.rs+++ b/frontend/rust-lib/flowy-grid/src/services/group/configuration.rs@@ -285,10 +285,11 @@ fn merge_groups(old_groups: &[GroupRevision], groups: Vec<Group>) -> MergeGroupR}// Find out the new groups- let new_groups = group_map.into_values();- for (index, group) in new_groups.into_iter().enumerate() {- merge_result.add_insert_group(index, group);- }+ group_map+ .into_values()+ .enumerate()+ .for_each(|(index, group)| merge_result.add_insert_group(index, group));+merge_result}diff --git a/shared-lib/lib-ot/src/core/document/attributes.rs b/shared-lib/lib-ot/src/core/document/attributes.rsindex 52b33dce08..d9242c67cc 100644--- a/shared-lib/lib-ot/src/core/document/attributes.rs+++ b/shared-lib/lib-ot/src/core/document/attributes.rs@@ -3,6 +3,12 @@ use std::collections::HashMap;#[derive(Clone, serde::Serialize, serde::Deserialize)]pub struct NodeAttributes(pub HashMap<String, Option<String>>);+impl Default for NodeAttributes {+ fn default() -> Self {+ Self::new()+ }+}+impl NodeAttributes {pub fn new() -> NodeAttributes {NodeAttributes(HashMap::new())diff --git a/shared-lib/lib-ot/src/core/document/document.rs b/shared-lib/lib-ot/src/core/document/document.rsindex 73ff03fe64..204a920ad8 100644--- a/shared-lib/lib-ot/src/core/document/document.rs+++ b/shared-lib/lib-ot/src/core/document/document.rs@@ -10,10 +10,16 @@ pub struct DocumentTree {pub root: NodeId,}+impl Default for DocumentTree {+ fn default() -> Self {+ Self::new()+ }+}+impl DocumentTree {pub fn new() -> DocumentTree {let mut arena = Arena::new();- let root = arena.new_node(NodeData::new("root".into()));+ let root = arena.new_node(NodeData::new("root"));DocumentTree { arena, root }}@@ -25,7 +31,7 @@ impl DocumentTree {let mut iterate_node = self.root;for id in &position.0 {- let child = self.child_at_index_of_path(iterate_node, id.clone());+ let child = self.child_at_index_of_path(iterate_node, *id);iterate_node = match child {Some(node) => node,None => return None,@@ -74,13 +80,10 @@ impl DocumentTree {fn child_at_index_of_path(&self, at_node: NodeId, index: usize) -> Option<NodeId> {let children = at_node.children(&self.arena);- let mut counter = 0;- for child in children {+ for (counter, child) in children.enumerate() {if counter == index {return Some(child);}-- counter += 1;}None@@ -107,7 +110,7 @@ impl DocumentTree {let last_index = path.0[path.0.len() - 1];let parent_node = self.node_at_path(&Position(parent_path.to_vec()))- .ok_or(ErrorBuilder::new(OTErrorCode::PathNotFound).build())?;+ .ok_or_else(|| ErrorBuilder::new(OTErrorCode::PathNotFound).build())?;self.insert_child_at_index(parent_node, last_index, nodes.as_ref())}@@ -132,7 +135,7 @@ impl DocumentTree {let node_to_insert = self.child_at_index_of_path(parent, index)- .ok_or(ErrorBuilder::new(OTErrorCode::PathNotFound).build())?;+ .ok_or_else(|| ErrorBuilder::new(OTErrorCode::PathNotFound).build())?;self.insert_subtree_before(&node_to_insert, insert_children);Ok(())@@ -160,11 +163,11 @@ impl DocumentTree {fn apply_update(&mut self, path: &Position, attributes: &NodeAttributes) -> Result<(), OTError> {let update_node = self.node_at_path(path)- .ok_or(ErrorBuilder::new(OTErrorCode::PathNotFound).build())?;+ .ok_or_else(|| ErrorBuilder::new(OTErrorCode::PathNotFound).build())?;let node_data = self.arena.get_mut(update_node).unwrap();let new_node = {let old_attributes = &node_data.get().attributes;- let new_attributes = NodeAttributes::compose(&old_attributes, attributes);+ let new_attributes = NodeAttributes::compose(old_attributes, attributes);NodeData {attributes: new_attributes,..node_data.get().clone()@@ -177,7 +180,7 @@ impl DocumentTree {fn apply_delete(&mut self, path: &Position, len: usize) -> Result<(), OTError> {let mut update_node = self.node_at_path(path)- .ok_or(ErrorBuilder::new(OTErrorCode::PathNotFound).build())?;+ .ok_or_else(|| ErrorBuilder::new(OTErrorCode::PathNotFound).build())?;for _ in 0..len {let next = update_node.following_siblings(&self.arena).next();update_node.remove_subtree(&mut self.arena);@@ -193,7 +196,7 @@ impl DocumentTree {fn apply_text_edit(&mut self, path: &Position, delta: &TextDelta) -> Result<(), OTError> {let edit_node = self.node_at_path(path)- .ok_or(ErrorBuilder::new(OTErrorCode::PathNotFound).build())?;+ .ok_or_else(|| ErrorBuilder::new(OTErrorCode::PathNotFound).build())?;let node_data = self.arena.get_mut(edit_node).unwrap();let new_delta = if let Some(old_delta) = &node_data.get().delta {Some(old_delta.compose(delta)?)diff --git a/shared-lib/lib-ot/src/core/document/position.rs b/shared-lib/lib-ot/src/core/document/position.rsindex b98edd97f4..541ff98fb2 100644--- a/shared-lib/lib-ot/src/core/document/position.rs+++ b/shared-lib/lib-ot/src/core/document/position.rs@@ -35,7 +35,8 @@ impl Position {prefix.push(b_at_index);}prefix.append(&mut suffix);- return Position(prefix);++ Position(prefix)}}diff --git a/shared-lib/lib-ot/src/core/document/transaction.rs b/shared-lib/lib-ot/src/core/document/transaction.rsindex 73fce7d8ad..c5b00523da 100644--- a/shared-lib/lib-ot/src/core/document/transaction.rs+++ b/shared-lib/lib-ot/src/core/document/transaction.rs@@ -63,7 +63,7 @@ impl<'a> TransactionBuilder<'a> {let mut deleted_nodes: Vec<Box<NodeSubTree>> = Vec::new();for _ in 0..length {- deleted_nodes.push(self.get_deleted_nodes(node.clone()));+ deleted_nodes.push(self.get_deleted_nodes(node));node = node.following_siblings(&self.document.arena).next().unwrap();}@@ -74,19 +74,12 @@ impl<'a> TransactionBuilder<'a> {}fn get_deleted_nodes(&self, node_id: NodeId) -> Box<NodeSubTree> {- let node = self.document.arena.get(node_id.clone()).unwrap();- let node_data = node.get();- let mut children: Vec<Box<NodeSubTree>> = vec![];+ let node_data = self.document.arena.get(node_id).unwrap().get();- let mut children_iterators = node_id.children(&self.document.arena);- loop {- let next_child = children_iterators.next();- if let Some(child_id) = next_child {- children.push(self.get_deleted_nodes(child_id));- } else {- break;- }- }+ let mut children: Vec<Box<NodeSubTree>> = vec![];+ node_id.children(&self.document.arena).for_each(|child_id| {+ children.push(self.get_deleted_nodes(child_id));+ });Box::new(NodeSubTree {node_type: node_data.node_type.clone(),