From ad4375240e21b602d4ee7f1350c37ec8e2472982 Mon Sep 17 00:00:00 2001 From: Rendo Date: Sun, 9 Nov 2025 13:31:55 +0500 Subject: [PATCH] small refactor --- src/lib.rs | 1 + src/node/mod.rs | 4 +-- src/node/node_modifier/errors.rs | 24 ++++++++++++++++ .../mod.rs} | 28 +++---------------- 4 files changed, 31 insertions(+), 26 deletions(-) create mode 100644 src/node/node_modifier/errors.rs rename src/node/{node_modifier.rs => node_modifier/mod.rs} (91%) diff --git a/src/lib.rs b/src/lib.rs index ac0c947..97ffda3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ pub mod formula; pub mod node; + #[cfg(test)] mod tests; diff --git a/src/node/mod.rs b/src/node/mod.rs index 293a6a0..c3bbfef 100644 --- a/src/node/mod.rs +++ b/src/node/mod.rs @@ -1,9 +1,9 @@ use std::fmt; -use crate::node::node_modifier::NodeModifier; use handler::*; +use node_modifier::NodeModifier; -mod handler; +pub(crate) mod handler; pub mod node_modifier; #[derive(Clone)] diff --git a/src/node/node_modifier/errors.rs b/src/node/node_modifier/errors.rs new file mode 100644 index 0000000..9faeca2 --- /dev/null +++ b/src/node/node_modifier/errors.rs @@ -0,0 +1,24 @@ +use std::fmt; + +use crate::node::Node; + +pub enum NodeManipulationError { + TooMuchChildren(Node), + NotEnoughChildren, + ProtectedEmpty, + IndexOutOfRange(usize), +} +impl fmt::Display for NodeManipulationError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + "{}", + match self { + NodeManipulationError::TooMuchChildren(node) => "Too much children", + NodeManipulationError::ProtectedEmpty => "Empty node is protected", + NodeManipulationError::NotEnoughChildren => "Not enough children", + NodeManipulationError::IndexOutOfRange(index) => "Index out of range", + } + ) + } +} diff --git a/src/node/node_modifier.rs b/src/node/node_modifier/mod.rs similarity index 91% rename from src/node/node_modifier.rs rename to src/node/node_modifier/mod.rs index 1f38a14..f63442e 100644 --- a/src/node/node_modifier.rs +++ b/src/node/node_modifier/mod.rs @@ -1,33 +1,13 @@ -use std::fmt; - use crate::node::Node; -use crate::node::NodeHandler; +use crate::node::handler::NodeHandler; +use errors::*; use rand::random_range; +pub mod errors; + const PICK_STOP_PROBABILITY: u8 = 2; const TYPE_CHANGE_PROBABILITY: u8 = 10; -pub enum NodeManipulationError { - TooMuchChildren(Node), - NotEnoughChildren, - ProtectedEmpty, - IndexOutOfRange(usize), -} -impl fmt::Display for NodeManipulationError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!( - f, - "{}", - match self { - NodeManipulationError::TooMuchChildren(node) => "Too much children", - NodeManipulationError::ProtectedEmpty => "Empty node is protected", - NodeManipulationError::NotEnoughChildren => "Not enough children", - NodeManipulationError::IndexOutOfRange(index) => "Index out of range", - } - ) - } -} - pub struct NodeModifier<'a> { picked_node: &'a mut Node, // This looks very monstrous, but it means "vector of functions for node paired with their maximum children count, if it exists"