• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Chik-Network / klvm_rs / 9969783315

17 Jul 2024 07:09AM UTC coverage: 91.834% (-2.2%) from 94.072%
9969783315

push

github

Chik-Network
update 0.2.5

1191 of 1284 new or added lines in 29 files covered. (92.76%)

66 existing lines in 11 files now uncovered.

4071 of 4433 relevant lines covered (91.83%)

3553.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.84
/src/node.rs
1
use super::allocator::{Allocator, NodePtr, SExp};
2
use std::fmt;
3

4
pub struct Node<'a> {
5
    pub allocator: &'a Allocator,
6
    pub node: NodePtr,
7
}
8

9
impl<'a> Node<'a> {
10
    pub fn new(allocator: &'a Allocator, node: NodePtr) -> Self {
349,278✔
11
        Node { allocator, node }
349,278✔
12
    }
349,278✔
13

14
    pub fn with_node(&self, node: NodePtr) -> Self {
296,504✔
15
        Node::new(self.allocator, node)
296,504✔
16
    }
296,504✔
17

18
    pub fn sexp(&self) -> SExp {
175,883✔
19
        self.allocator.sexp(self.node)
175,883✔
20
    }
175,883✔
21

22
    pub fn atom(&self) -> Option<&'a [u8]> {
24,294✔
23
        match self.sexp() {
24,294✔
24
            SExp::Atom(_) => Some(self.allocator.atom(self.node)),
24,226✔
25
            _ => None,
68✔
26
        }
27
    }
24,294✔
28

29
    pub fn pair(&self) -> Option<(Node<'a>, Node<'a>)> {
95,626✔
30
        match self.sexp() {
95,626✔
31
            SExp::Pair(left, right) => Some((self.with_node(left), self.with_node(right))),
80,294✔
32
            _ => None,
15,332✔
33
        }
34
    }
95,626✔
35

36
    pub fn nullp(&self) -> bool {
6,426✔
37
        match self.sexp() {
6,426✔
38
            SExp::Atom(a) => a.is_empty(),
6,123✔
39
            _ => false,
303✔
40
        }
41
    }
6,426✔
42

43
    pub fn arg_count_is(&self, mut count: usize) -> bool {
4,044✔
44
        let mut ptr: Self = self.clone();
4,044✔
45
        loop {
46
            if count == 0 {
12,162✔
47
                return ptr.nullp();
4,037✔
48
            }
8,125✔
49
            match ptr.sexp() {
8,125✔
50
                SExp::Pair(_, new_ptr) => {
8,118✔
51
                    ptr = ptr.with_node(new_ptr).clone();
8,118✔
52
                }
8,118✔
53
                _ => return false,
7✔
54
            }
55
            count -= 1;
8,118✔
56
        }
57
    }
4,044✔
58

59
    pub fn null(&self) -> Self {
15✔
60
        self.with_node(self.allocator.null())
15✔
61
    }
15✔
62

63
    pub fn one(&self) -> Self {
14✔
64
        self.with_node(self.allocator.one())
14✔
65
    }
14✔
66

67
    pub fn as_bool(&self) -> bool {
43✔
68
        match self.atom() {
43✔
69
            Some(v0) => !v0.is_empty(),
36✔
70
            _ => true,
7✔
71
        }
72
    }
43✔
73

74
    pub fn from_bool(&self, b: bool) -> Self {
29✔
75
        if b {
29✔
76
            self.one()
14✔
77
        } else {
78
            self.null()
15✔
79
        }
80
    }
29✔
81
}
82

83
impl<'a> fmt::Debug for Node<'a> {
NEW
84
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
×
NEW
85
        match self.sexp() {
×
NEW
86
            SExp::Pair(l, r) => f
×
NEW
87
                .debug_tuple("")
×
NEW
88
                .field(&self.with_node(l))
×
NEW
89
                .field(&self.with_node(r))
×
NEW
90
                .finish(),
×
NEW
91
            SExp::Atom(a) => self.allocator.buf(&a).fmt(f),
×
92
        }
NEW
93
    }
×
94
}
95

96
impl<'a> Clone for Node<'a> {
97
    fn clone(&self) -> Self {
47,920✔
98
        self.with_node(self.node)
47,920✔
99
    }
47,920✔
100
}
101

102
impl<'a> IntoIterator for &Node<'a> {
103
    type Item = Node<'a>;
104
    type IntoIter = Node<'a>;
105

106
    fn into_iter(self) -> Self::IntoIter {
185✔
107
        self.clone()
185✔
108
    }
185✔
109
}
110

111
impl<'a> Iterator for Node<'a> {
112
    type Item = Node<'a>;
113

114
    fn next(&mut self) -> Option<Self::Item> {
13,116✔
115
        match self.pair() {
13,116✔
116
            Some((first, rest)) => {
8,770✔
117
                self.node = rest.node;
8,770✔
118
                Some(first)
8,770✔
119
            }
120
            _ => None,
4,346✔
121
        }
122
    }
13,116✔
123
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc