small refactor
This commit is contained in:
parent
571c3863c0
commit
ad4375240e
4 changed files with 31 additions and 26 deletions
|
|
@ -1,4 +1,5 @@
|
|||
pub mod formula;
|
||||
pub mod node;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
|
|
|||
|
|
@ -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)]
|
||||
|
|
|
|||
24
src/node/node_modifier/errors.rs
Normal file
24
src/node/node_modifier/errors.rs
Normal 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",
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -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"
|
||||
Loading…
Add table
Add a link
Reference in a new issue