pub trait EntrylikeExt: Entrylike {
// Provided methods
fn entry_eq<OtherEntry>(&self, other: &OtherEntry) -> bool
where OtherEntry: Entrylike { ... }
fn entry_ne<OtherEntry>(&self, other: &OtherEntry) -> bool
where OtherEntry: Entrylike { ... }
fn cmp_recency<OtherEntry>(&self, other: &OtherEntry) -> Ordering
where OtherEntry: Entrylike { ... }
fn is_newer_than<OtherEntry>(&self, other: &OtherEntry) -> bool
where OtherEntry: Entrylike { ... }
fn is_older_than<OtherEntry>(&self, other: &OtherEntry) -> bool
where OtherEntry: Entrylike { ... }
fn prunes<OtherEntry>(&self, other: &OtherEntry) -> bool
where OtherEntry: Entrylike { ... }
fn is_pruned_by<OtherEntry>(&self, other: &OtherEntry) -> bool
where OtherEntry: Entrylike,
Self: Sized { ... }
fn authorise(
&self,
write_capability: &WriteCapability,
secret: &SubspaceSecret,
) -> Result<AuthorisedEntry, DoesNotAuthorise> { ... }
async fn encode_entry<C>(&self, consumer: &mut C) -> Result<(), C::Error>
where C: BulkConsumer<Item = u8> + ?Sized { ... }
fn length_of_entry_encoding(&self) -> usize { ... }
}Expand description
Methods for working with Entrylikes.
This trait is automatically implemented by all types implementing Entrylike.
Provided Methods§
Sourcefn entry_eq<OtherEntry>(&self, other: &OtherEntry) -> boolwhere
OtherEntry: Entrylike,
fn entry_eq<OtherEntry>(&self, other: &OtherEntry) -> boolwhere
OtherEntry: Entrylike,
Returns whether self and other describe equal entries.
§Examples
use willow25::prelude::*;
let entry = Entry::builder()
.namespace_id([0; 32].into())
.subspace_id([1; 32].into())
.path(path!(""))
.timestamp(12345)
.payload_digest([1; 32].into())
.payload_length(17)
.build();
assert!(entry.entry_eq(&entry));
let changed = Entry::prefilled_builder(&entry).timestamp(999999).build();
assert!(!entry.entry_eq(&changed));
Sourcefn entry_ne<OtherEntry>(&self, other: &OtherEntry) -> boolwhere
OtherEntry: Entrylike,
fn entry_ne<OtherEntry>(&self, other: &OtherEntry) -> boolwhere
OtherEntry: Entrylike,
Returns whether self and other describe non-equal entries.
§Examples
use willow25::prelude::*;
let entry = Entry::builder()
.namespace_id([0; 32].into())
.subspace_id([1; 32].into())
.path(path!(""))
.timestamp(12345)
.payload_digest([1; 32].into())
.payload_length(17)
.build();
assert!(!entry.entry_ne(&entry));
let changed = Entry::prefilled_builder(&entry).timestamp(999999).build();
assert!(entry.entry_ne(&changed));
Sourcefn cmp_recency<OtherEntry>(&self, other: &OtherEntry) -> Orderingwhere
OtherEntry: Entrylike,
fn cmp_recency<OtherEntry>(&self, other: &OtherEntry) -> Orderingwhere
OtherEntry: Entrylike,
Compares self to another entry by timestamp, payload_digest (in case of a tie), and payload_length third (in case of yet another tie). See also EntrylikeExt::is_newer_than and EntrylikeExt::is_older_than.
Comparing recency is primarily important to determine which entries overwrite each other; the EntrylikeExt::prunes method checks for that directly.
§Examples
use core::cmp::Ordering;
use willow25::prelude::*;
let entry = Entry::builder()
.namespace_id([0; 32].into())
.subspace_id([1; 32].into())
.path(path!(""))
.timestamp(12345)
.payload_digest([1; 32].into())
.payload_length(17)
.build();
assert_eq!(entry.cmp_recency(&entry), Ordering::Equal);
let lesser_timestamp = Entry::prefilled_builder(&entry).timestamp(5).build();
assert_eq!(entry.cmp_recency(&lesser_timestamp), Ordering::Greater);
let lesser_digest = Entry::prefilled_builder(&entry).payload_digest([0; 32].into()).build();
assert_eq!(entry.cmp_recency(&lesser_digest), Ordering::Greater);
let lesser_length = Entry::prefilled_builder(&entry).payload_length(0).build();
assert_eq!(entry.cmp_recency(&lesser_length), Ordering::Greater);
let greater_timestamp = Entry::prefilled_builder(&entry).timestamp(999999).build();
assert_eq!(entry.cmp_recency(&greater_timestamp), Ordering::Less);
let greater_digest = Entry::prefilled_builder(&entry).payload_digest([2; 32].into()).build();
assert_eq!(entry.cmp_recency(&greater_digest), Ordering::Less);
let greater_length = Entry::prefilled_builder(&entry).payload_length(99).build();
assert_eq!(entry.cmp_recency(&greater_length), Ordering::Less);Sourcefn is_newer_than<OtherEntry>(&self, other: &OtherEntry) -> boolwhere
OtherEntry: Entrylike,
fn is_newer_than<OtherEntry>(&self, other: &OtherEntry) -> boolwhere
OtherEntry: Entrylike,
Returns whether this entry is strictly newer than another entry. See also EntrylikeExt::cmp_recency and EntrylikeExt::is_older_than.
Comparing recency is primarily important to determine which entries overwrite each other; the EntrylikeExt::prunes method checks for that directly.
§Examples
use willow25::prelude::*;
let entry = Entry::builder()
.namespace_id([0; 32].into())
.subspace_id([1; 32].into())
.path(path!(""))
.timestamp(12345)
.payload_digest([1; 32].into())
.payload_length(17)
.build();
assert!(!entry.is_newer_than(&entry));
let lesser_timestamp = Entry::prefilled_builder(&entry).timestamp(5).build();
assert!(entry.is_newer_than(&lesser_timestamp));
let lesser_digest = Entry::prefilled_builder(&entry).payload_digest([0; 32].into()).build();
assert!(entry.is_newer_than(&lesser_digest));
let lesser_length = Entry::prefilled_builder(&entry).payload_length(0).build();
assert!(entry.is_newer_than(&lesser_length));
let greater_timestamp = Entry::prefilled_builder(&entry).timestamp(999999).build();
assert!(!entry.is_newer_than(&greater_timestamp));
let greater_digest = Entry::prefilled_builder(&entry).payload_digest([2; 32].into()).build();
assert!(!entry.is_newer_than(&greater_digest));
let greater_length = Entry::prefilled_builder(&entry).payload_length(99).build();
assert!(!entry.is_newer_than(&greater_length));Sourcefn is_older_than<OtherEntry>(&self, other: &OtherEntry) -> boolwhere
OtherEntry: Entrylike,
fn is_older_than<OtherEntry>(&self, other: &OtherEntry) -> boolwhere
OtherEntry: Entrylike,
Returns whether this entry is strictly older than another entry. See also EntrylikeExt::cmp_recency and EntrylikeExt::is_newer_than.
Comparing recency is primarily important to determine which entries overwrite each other; the EntrylikeExt::prunes method checks for that directly.
§Examples
use willow25::prelude::*;
let entry = Entry::builder()
.namespace_id([0; 32].into())
.subspace_id([1; 32].into())
.path(path!(""))
.timestamp(12345)
.payload_digest([1; 32].into())
.payload_length(17)
.build();
assert!(!entry.is_older_than(&entry));
let lesser_timestamp = Entry::prefilled_builder(&entry).timestamp(5).build();
assert!(!entry.is_older_than(&lesser_timestamp));
let lesser_digest = Entry::prefilled_builder(&entry).payload_digest([0; 32].into()).build();
assert!(!entry.is_older_than(&lesser_digest));
let lesser_length = Entry::prefilled_builder(&entry).payload_length(0).build();
assert!(!entry.is_older_than(&lesser_length));
let greater_timestamp = Entry::prefilled_builder(&entry).timestamp(999999).build();
assert!(entry.is_older_than(&greater_timestamp));
let greater_digest = Entry::prefilled_builder(&entry).payload_digest([2; 32].into()).build();
assert!(entry.is_older_than(&greater_digest));
let greater_length = Entry::prefilled_builder(&entry).payload_length(99).build();
assert!(entry.is_older_than(&greater_length));Sourcefn prunes<OtherEntry>(&self, other: &OtherEntry) -> boolwhere
OtherEntry: Entrylike,
fn prunes<OtherEntry>(&self, other: &OtherEntry) -> boolwhere
OtherEntry: Entrylike,
Returns whether this entry would prefix prune another entry.
Prefix pruning powers deletion in Willow: whenever a data store would contain two entries, one of which pruens the other, the other is removed from the data store (or never inserted in the first place). Informally speaking, newer entries remove older entries, but only if they are in the same namespace and subspace, and only if the path of the newer entry is a prefix of the path of the older entry.
More precisely: an entry e1 prunes an entry e2 if and only if
e1.namespace_id() == e2.namespace_id(),e1.subspace_id() == e2.subspace_id(),e1.path().is_prefix_of(e2.path()), ande1.is_newer_than(&e2).
This method is the reciprocal of EntrylikeExt::is_pruned_by.
§Examples
use willow25::prelude::*;
let entry = Entry::builder()
.namespace_id([0; 32].into())
.subspace_id([1; 32].into())
.path(path!("/a/b"))
.timestamp(12345)
.payload_digest([1; 32].into())
.payload_length(17)
.build();
let newer = Entry::prefilled_builder(&entry).timestamp(99999).build();
assert!(!entry.prunes(&newer));
assert!(newer.prunes(&entry));
let newer_and_prefix = Entry::prefilled_builder(&newer)
.path(path!("/a")).build();
assert!(!entry.prunes(&newer_and_prefix));
assert!(newer_and_prefix.prunes(&entry));
let newer_and_extension = Entry::prefilled_builder(&newer)
.path(path!("/a/b/c")).build();
assert!(!entry.prunes(&newer_and_extension));
assert!(!newer_and_extension.prunes(&entry));
let newer_but_unrelated_namespace = Entry::prefilled_builder(&newer)
.namespace_id([17; 32].into()).build();
assert!(!entry.prunes(&newer_but_unrelated_namespace));
assert!(!newer_but_unrelated_namespace.prunes(&entry));
let newer_but_unrelated_subspace = Entry::prefilled_builder(&newer)
.subspace_id([3; 32].into()).build();
assert!(!entry.prunes(&newer_but_unrelated_subspace));
assert!(!newer_but_unrelated_subspace.prunes(&entry));Sourcefn is_pruned_by<OtherEntry>(&self, other: &OtherEntry) -> bool
fn is_pruned_by<OtherEntry>(&self, other: &OtherEntry) -> bool
Returns whether this entry would be prefix pruned by another entry.
Prefix pruning powers deletion in Willow: whenever a data store would contain two entries, one of which pruens the other, the other is removed from the data store (or never inserted in the first place). Informally speaking, newer entries remove older entries, but only if they are in the same namespace and subspace, and only if the path of the newer entry is a prefix of the path of the older entry.
More precisely: an entry e1 prunes an entry e2 if and only if
e1.namespace_id() == e2.namespace_id(),e1.subspace_id() == e2.subspace_id(),e1.path().is_prefix_of(e2.path()), ande1.is_newer_than(&e2).
This method is the reciprocal of EntrylikeExt::prunes.
§Examples
use willow25::prelude::*;
let entry = Entry::builder()
.namespace_id([0; 32].into())
.subspace_id([1; 32].into())
.path(path!("/a/b"))
.timestamp(12345)
.payload_digest([1; 32].into())
.payload_length(17)
.build();
let newer = Entry::prefilled_builder(&entry).timestamp(99999).build();
assert!(entry.is_pruned_by(&newer));
assert!(!newer.is_pruned_by(&entry));
let newer_and_prefix = Entry::prefilled_builder(&newer)
.path(path!("/a")).build();
assert!(entry.is_pruned_by(&newer_and_prefix));
assert!(!newer_and_prefix.is_pruned_by(&entry));
let newer_and_extension = Entry::prefilled_builder(&newer)
.path(path!("/a/b/c")).build();
assert!(!entry.is_pruned_by(&newer_and_extension));
assert!(!newer_and_extension.is_pruned_by(&entry));
let newer_but_unrelated_namespace = Entry::prefilled_builder(&newer)
.namespace_id([17; 32].into()).build();
assert!(!entry.is_pruned_by(&newer_but_unrelated_namespace));
assert!(!newer_but_unrelated_namespace.is_pruned_by(&entry));
let newer_but_unrelated_subspace = Entry::prefilled_builder(&newer)
.subspace_id([3; 32].into()).build();
assert!(!entry.is_pruned_by(&newer_but_unrelated_subspace));
assert!(!newer_but_unrelated_subspace.is_pruned_by(&entry));Turns self into an AuthorisedEntry by creating an authorisation token for it.
use rand::rngs::OsRng;
use willow25::prelude::*;
use willow25::authorisation::PossiblyAuthorisedEntry;
let mut csprng = OsRng;
let (subspace_id, secret) = randomly_generate_subspace(&mut csprng);
let namespace_id = NamespaceId::from_bytes(&[17; 32]);
let entry = Entry::builder()
.namespace_id(namespace_id.clone())
.subspace_id(subspace_id.clone())
.path(path!("/ideas"))
.timestamp(12345)
.payload(b"chocolate with mustard")
.build();
let mut cap = WriteCapability::new_communal(
namespace_id.clone(),
subspace_id.clone(),
);
let authed = entry.authorise(&cap, &secret).unwrap();
assert_eq!(authed.entry(), &entry);Sourceasync fn encode_entry<C>(&self, consumer: &mut C) -> Result<(), C::Error>
async fn encode_entry<C>(&self, consumer: &mut C) -> Result<(), C::Error>
Encodes self according to the encode_entry encoding function.
Sourcefn length_of_entry_encoding(&self) -> usize
fn length_of_entry_encoding(&self) -> usize
Computes the length of the encoding of self according to the encode_entry encoding function.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".