Struct Id

Source
pub struct Id(/* private fields */);
Expand description

Bytes

Implementations§

Source§

impl Id

Source

pub fn new(bytes: [u8; 32]) -> Self

👎Deprecated since 1.0.0: Use from_byte_array instead

Construct from byte array

Source

pub const fn from_byte_array(bytes: [u8; 32]) -> Self

Construct event ID from 32-byte array

Source

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}
Source

pub fn to_bytes(self) -> [u8; 32]

Return the inner value

Source

pub fn as_bytes(&self) -> &[u8; 32]

Return reference to the inner value

Trait Implementations§

Source§

impl Clone for Id

Source§

fn clone(&self) -> Id

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Id

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Id

Source§

fn default() -> Id

Returns the “default value” for a type. Read more
Source§

impl Deref for Id

Source§

type Target = [u8; 32]

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for Id

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl Hash for Id

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Id

Source§

fn cmp(&self, other: &Id) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Id

Source§

fn eq(&self, other: &Id) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Id

Source§

fn partial_cmp(&self, other: &Id) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for Id

Source§

impl Eq for Id

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.