small refactor

This commit is contained in:
Rendo 2025-11-09 13:31:55 +05:00
commit ad4375240e
4 changed files with 31 additions and 26 deletions

View file

@ -1,4 +1,5 @@
pub mod formula;
pub mod node;
#[cfg(test)]
mod tests;

View file

@ -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)]

View file

@ -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",
}
)
}
}

View file

@ -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"