Skip to main content

RecordSet

Struct RecordSet 

Source
pub struct RecordSet<T> { /* private fields */ }
Expand description

A container that lets callers organize records by identifier.

§Deduplication by identifier

The same EntryId appearing twice in one payload is legal: it can carry one version of the entry per device. A merge can only apply one result, so which one is used has to be fixed first: first-inserted wins, and whoever builds the payload is responsible for putting the version it wants adopted first.

Last-inserted-wins is not used: that would make the order inside a payload a security-relevant property (the last record decides), while the peer controls that order.

§Genericity

Two places need a “record set deduplicated by identifier”, with different element types:

  • MergedRecord: the semantic record after decryption, used by the merge layer.
  • crate::sync::Record: the wire-format record that is still encrypted, used by payload packing and parsing.

One generic container instead of two implementations is not just less code: the two deduplication rules must be identical (both are first-inserted wins), and two implementations would silently drift apart, showing up as a payload deduplicated on the sending side and not on the receiving side — a failure that reproduces only on the peer.

Implementations§

Source§

impl<T: HasEntryId> RecordSet<T>

Source

pub fn new() -> Self

An empty set.

Source

pub fn insert(&mut self, record: T) -> bool

Inserts a record; does not overwrite when the same ID already exists.

Returns whether the record was actually inserted (false means this ID is already present).

Source

pub fn len(&self) -> usize

How many records there are.

Source

pub fn is_empty(&self) -> bool

Whether the set is empty.

Source

pub fn get(&self, id: &EntryId) -> Option<&T>

Borrows the record for one ID.

Source

pub fn iter(&self) -> impl Iterator<Item = (&EntryId, &T)>

Iterates in ID order.

A BTreeMap rather than a HashMap: the iteration order has to be deterministic, otherwise the same payload would produce a different merge order on different devices and the order of the conflict list would follow; for the wire format it would also make two payloads with identical content produce different plaintext.

Trait Implementations§

Source§

impl<T: Debug> Debug for RecordSet<T>

Source§

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

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

impl<T> Default for RecordSet<T>

Source§

fn default() -> Self

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

impl<'a, T> IntoIterator for &'a RecordSet<T>

Source§

fn into_iter(self) -> Self::IntoIter

Borrows every record in ID order.

Borrowing rather than a records() -> Vec<T>: the latter requires every record to be copyable, and both element types deliberately have no Clone (they hold key material). Borrowing lets merge_into take a &RecordSet directly, without copying the key material of a whole payload just to pass it around — one sync would copy hundreds of seeds for no reason at all.

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Values<'a, EntryId, T>

Which kind of iterator are we turning this into?

Auto Trait Implementations§

§

impl<T> Freeze for RecordSet<T>
where BTreeMap<EntryId, T>: Freeze,

§

impl<T> RefUnwindSafe for RecordSet<T>

§

impl<T> Send for RecordSet<T>
where BTreeMap<EntryId, T>: Send,

§

impl<T> Sync for RecordSet<T>
where BTreeMap<EntryId, T>: Sync,

§

impl<T> Unpin for RecordSet<T>
where BTreeMap<EntryId, T>: Unpin,

§

impl<T> UnsafeUnpin for RecordSet<T>

§

impl<T> UnwindSafe for RecordSet<T>

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> 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<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.