fuel_merkle/binary/
primitive.rs1use crate::{
2 binary::Node,
3 common::{
4 Bytes32,
5 Position,
6 },
7};
8
9pub type Primitive = (u64, Bytes32);
10
11pub trait PrimitiveView {
12 fn position(&self) -> Position;
13 fn hash(&self) -> &Bytes32;
14}
15
16impl PrimitiveView for Primitive {
17 fn position(&self) -> Position {
18 Position::from_in_order_index(self.0)
19 }
20
21 fn hash(&self) -> &Bytes32 {
22 &self.1
23 }
24}
25
26impl From<&Node> for Primitive {
27 fn from(node: &Node) -> Self {
28 (node.position().in_order_index(), *node.hash())
29 }
30}
31
32impl From<Primitive> for Node {
33 fn from(primitive: Primitive) -> Self {
34 let position = primitive.position();
35 let hash = *primitive.hash();
36 Node::new(position, hash)
37 }
38}