pub struct Id(/* private fields */);
Expand description
Bytes
Implementations§
Source§impl Id
impl Id
Sourcepub fn new(bytes: [u8; 32]) -> Self
👎Deprecated since 1.0.0: Use from_byte_array
instead
pub fn new(bytes: [u8; 32]) -> Self
from_byte_array
insteadConstruct from byte array
Sourcepub const fn from_byte_array(bytes: [u8; 32]) -> Self
pub const fn from_byte_array(bytes: [u8; 32]) -> Self
Construct event ID from 32-byte array
Sourcepub fn from_slice(slice: &[u8]) -> Result<Self, Error>
pub fn from_slice(slice: &[u8]) -> Result<Self, Error>
Construct from slice
Examples found in repository?
examples/negentropy.rs (line 12)
6fn main() {
7 // Client
8 let mut storage_client = NegentropyStorageVector::new();
9 storage_client
10 .insert(
11 0,
12 Id::from_slice(b"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").unwrap(),
13 )
14 .unwrap();
15 storage_client
16 .insert(
17 1,
18 Id::from_slice(b"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb").unwrap(),
19 )
20 .unwrap();
21 storage_client.seal().unwrap();
22 let mut client = Negentropy::borrowed(&storage_client, 0).unwrap();
23 let init_output = client.initiate().unwrap();
24 println!("Initiator Output: {:x?}", init_output.clone());
25
26 // Relay
27 let mut storage_relay = NegentropyStorageVector::new();
28 storage_relay
29 .insert(
30 0,
31 Id::from_slice(b"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").unwrap(),
32 )
33 .unwrap();
34 storage_relay
35 .insert(
36 2,
37 Id::from_slice(b"cccccccccccccccccccccccccccccccc").unwrap(),
38 )
39 .unwrap();
40 storage_relay
41 .insert(
42 3,
43 Id::from_slice(b"11111111111111111111111111111111").unwrap(),
44 )
45 .unwrap();
46 storage_relay
47 .insert(
48 5,
49 Id::from_slice(b"22222222222222222222222222222222").unwrap(),
50 )
51 .unwrap();
52 storage_relay
53 .insert(
54 10,
55 Id::from_slice(b"33333333333333333333333333333333").unwrap(),
56 )
57 .unwrap();
58 storage_relay.seal().unwrap();
59 let mut relay = Negentropy::borrowed(&storage_relay, 0).unwrap();
60 let reconcile_output = relay.reconcile(&init_output).unwrap();
61 println!("Reconcile Output: {:x?}", reconcile_output.clone());
62
63 // Client
64 let mut have_ids = Vec::new();
65 let mut need_ids = Vec::new();
66 client
67 .reconcile_with_ids(&reconcile_output, &mut have_ids, &mut need_ids)
68 .unwrap();
69 println!(
70 "Have IDs: {}",
71 have_ids
72 .into_iter()
73 .map(|b| format!("{:x?}", b))
74 .collect::<Vec<_>>()
75 .join("")
76 );
77 println!(
78 "Need IDs: {}",
79 need_ids
80 .into_iter()
81 .map(|b| format!("{:x?}", b))
82 .collect::<Vec<_>>()
83 .join("")
84 );
85}
Trait Implementations§
Source§impl Ord for Id
impl Ord for Id
Source§impl PartialOrd for Id
impl PartialOrd for Id
impl Copy for Id
impl Eq for Id
impl StructuralPartialEq for Id
Auto Trait Implementations§
impl Freeze for Id
impl RefUnwindSafe for Id
impl Send for Id
impl Sync for Id
impl Unpin for Id
impl UnwindSafe for Id
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