1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#![deny(unused_extern_crates)]
#![warn(
missing_debug_implementations,
missing_docs,
rust_2018_idioms,
unreachable_pub
)]
#[macro_use]
extern crate failure;
#[macro_use]
extern crate lazy_static;
pub mod iota_units;
mod trinary;
pub mod trytes_converter;
pub mod unit_converter;
pub use trinary::*;
type Result<T> = ::std::result::Result<T, failure::Error>;
pub fn value(trits: &[i8]) -> i8 {
trits.iter().rev().fold(0, |acc, trit| acc * 3 + *trit)
}
pub fn long_value(trits: &[i8]) -> i64 {
trits
.iter()
.rev()
.fold(0, |acc, trit| acc * 3 + i64::from(*trit))
}