pub struct Natural { /* private fields */ }Implementations§
Source§impl Natural
impl Natural
Sourcepub fn from_n(value: usize) -> Self
pub fn from_n(value: usize) -> Self
Examples found in repository?
examples/ast_tester.rs (line 17)
13fn test_simple_binary_operation() {
14 debug!("Test: Simple binary operation '23 - 45'");
15
16 // Create token instances
17 let num_23 = Natural::from_n(23);
18 let subtract_op = MathOp::Subtract;
19 let num_45 = Natural::from_n(45);
20
21 // Create leaf nodes
22 let leaf_23 = Node::leaf(num_23);
23 let leaf_45 = Node::leaf(num_45);
24
25 // Create operation node
26 let mut op_node = Node::new(subtract_op);
27 op_node.add_child(leaf_23);
28 op_node.add_child(leaf_45);
29
30 // Create AST
31 let ast = AST::with_root(op_node);
32
33 // Print AST structure using Display trait
34 trace!("{}", ast);
35}
36
37/// Test 2: Binary operation with different number types "3.4 + 1"
38fn test_binary_operation_with_different_types() {
39 debug!("Test: Binary operation with different number types '3.4 + 1'");
40
41 // Create token instances
42 let real_3_4 = Real::from_n(3.4);
43 let add_op = MathOp::Add;
44 let num_1 = Natural::from_n(1);
45
46 // Build tree directly with constructor methods
47 let leaf_3_4 = Node::leaf(real_3_4);
48 let leaf_1 = Node::leaf(num_1);
49
50 let op_node = Node::branch(add_op, vec![leaf_3_4, leaf_1]);
51
52 // Create AST
53 let ast = AST::with_root(op_node);
54
55 // Print AST structure using Display trait
56 trace!("{}", ast);
57}
58
59/// Test 3: More complex expression "25.1 * 42 - 13"
60fn test_complex_expression() {
61 debug!("Test: Complex expression '25.1 * 42 - 13'");
62
63 // Create token instances
64 let real_25_1 = Real::from_n(25.1);
65 let multiply_op = MathOp::Multiply;
66 let num_42 = Natural::from_n(42);
67 let subtract_op = MathOp::Subtract;
68 let num_13 = Natural::from_n(13);
69
70 // Create leaf nodes
71 let leaf_25_1 = Node::leaf(real_25_1);
72 let leaf_42 = Node::leaf(num_42);
73 let leaf_13 = Node::leaf(num_13);
74
75 // Create multiplication operation
76 let mul_node = Node::branch(multiply_op, vec![leaf_25_1, leaf_42]);
77
78 // Create subtraction as the root operation
79 let root_node = Node::branch(subtract_op, vec![mul_node, leaf_13]);
80
81 // Create AST
82 let ast = AST::with_root(root_node);
83
84 // Print AST structure using Display trait
85 trace!("{}", ast);
86}Trait Implementations§
impl StructuralPartialEq for Natural
Auto Trait Implementations§
impl Freeze for Natural
impl RefUnwindSafe for Natural
impl Send for Natural
impl Sync for Natural
impl Unpin for Natural
impl UnwindSafe for Natural
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more