Show More
@@ -66,7 +66,7 b' fn bench(index: &Index, nm: &NodeTree, q' | |||
|
66 | 66 | .collect(); |
|
67 | 67 | if queries < 10 { |
|
68 | 68 | let nodes_hex: Vec<String> = |
|
69 |
nodes.iter().map(|n| n |
|
|
69 | nodes.iter().map(|n| format!("{:x}", n)).collect(); | |
|
70 | 70 | println!("Nodes: {:?}", nodes_hex); |
|
71 | 71 | } |
|
72 | 72 | let mut last: Option<Revision> = None; |
@@ -76,11 +76,11 b' fn bench(index: &Index, nm: &NodeTree, q' | |||
|
76 | 76 | } |
|
77 | 77 | let elapsed = start.elapsed(); |
|
78 | 78 | println!( |
|
79 |
"Did {} queries in {:?} (mean {:?}), last was {: |
|
|
79 | "Did {} queries in {:?} (mean {:?}), last was {:x} with result {:?}", | |
|
80 | 80 | queries, |
|
81 | 81 | elapsed, |
|
82 | 82 | elapsed / (queries as u32), |
|
83 |
nodes.last().unwrap() |
|
|
83 | nodes.last().unwrap(), | |
|
84 | 84 | last |
|
85 | 85 | ); |
|
86 | 86 | } |
@@ -11,6 +11,7 b'' | |||
|
11 | 11 | use bytes_cast::BytesCast; |
|
12 | 12 | use hex::{self, FromHex, FromHexError}; |
|
13 | 13 | use std::convert::TryFrom; |
|
14 | use std::fmt; | |
|
14 | 15 | |
|
15 | 16 | /// The length in bytes of a `Node` |
|
16 | 17 | /// |
@@ -80,6 +81,15 b" impl<'a> TryFrom<&'a [u8]> for &'a Node " | |||
|
80 | 81 | } |
|
81 | 82 | } |
|
82 | 83 | |
|
84 | impl fmt::LowerHex for Node { | |
|
85 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | |
|
86 | for &byte in &self.data { | |
|
87 | write!(f, "{:02x}", byte)? | |
|
88 | } | |
|
89 | Ok(()) | |
|
90 | } | |
|
91 | } | |
|
92 | ||
|
83 | 93 | #[derive(Debug, PartialEq)] |
|
84 | 94 | pub enum NodeError { |
|
85 | 95 | ExactLengthRequired(usize, String), |
@@ -124,14 +134,6 b' impl Node {' | |||
|
124 | 134 | .into()) |
|
125 | 135 | } |
|
126 | 136 | |
|
127 | /// Convert to hexadecimal string representation | |
|
128 | /// | |
|
129 | /// To be used in FFI and I/O only, in order to facilitate future | |
|
130 | /// changes of hash format. | |
|
131 | pub fn encode_hex(&self) -> String { | |
|
132 | hex::encode(self.data) | |
|
133 | } | |
|
134 | ||
|
135 | 137 | /// Provide access to binary data |
|
136 | 138 | /// |
|
137 | 139 | /// This is needed by FFI layers, for instance to return expected |
@@ -349,7 +351,7 b' mod tests {' | |||
|
349 | 351 | |
|
350 | 352 | #[test] |
|
351 | 353 | fn test_node_encode_hex() { |
|
352 |
assert_eq!(sample_node() |
|
|
354 | assert_eq!(format!("{:x}", sample_node()), sample_node_hex()); | |
|
353 | 355 | } |
|
354 | 356 | |
|
355 | 357 | #[test] |
@@ -391,7 +393,7 b' mod tests {' | |||
|
391 | 393 | "testgr".to_string() |
|
392 | 394 | )) |
|
393 | 395 | ); |
|
394 |
let mut long = NULL_NODE |
|
|
396 | let mut long = format!("{:x}", NULL_NODE); | |
|
395 | 397 | long.push('c'); |
|
396 | 398 | match NodePrefix::from_hex(&long) |
|
397 | 399 | .expect_err("should be refused as too long") |
General Comments 0
You need to be logged in to leave comments.
Login now