Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

[v2.0] Move exchange keys into User #251

Merged
merged 6 commits into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions streams/src/api/cursor_store.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Rust
use core::fmt;

// 3rd-party
use hashbrown::HashMap;

// IOTA

// Streams
use lets::id::Identifier;

// Local

#[derive(Default, Clone, PartialEq, Eq)]
pub(crate) struct CursorStore(HashMap<Identifier, usize>);

impl CursorStore {
pub(crate) fn new() -> Self {
Default::default()
}

pub(crate) fn is_cursor_tracked(&self, id: &Identifier) -> bool {
self.0.contains_key(id)
}

pub(crate) fn get_cursor(&self, id: &Identifier) -> Option<usize> {
self.0.get(id).copied()
}

pub(crate) fn insert_cursor(&mut self, id: Identifier, cursor: usize) -> bool {
self.0.insert(id, cursor).is_none()
}

pub(crate) fn cursors(&self) -> impl Iterator<Item = (Identifier, usize)> + ExactSizeIterator + Clone + '_ {
self.0.iter().map(|(identifier, cursor)| (*identifier, *cursor))
}

pub(crate) fn remove(&mut self, id: &Identifier) -> bool {
self.0.remove(id).is_some()
}
}

impl fmt::Debug for CursorStore {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "* cursors:")?;
for (id, cursor) in self.cursors() {
writeln!(f, "\t{:?} => {}", id, cursor)?;
}
Ok(())
}
}
82 changes: 0 additions & 82 deletions streams/src/api/key_store.rs

This file was deleted.

2 changes: 1 addition & 1 deletion streams/src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// Identifier Key storage. Used for keeping track of channel state
mod key_store;
mod cursor_store;

pub(crate) mod message;
mod messages;
Expand Down
Loading