refactor sync-server into a lib crate with a binary

This commit is contained in:
Dustin J. Mitchell
2021-09-07 02:44:38 +00:00
parent 4690cf7fc8
commit ebcf9527dc
8 changed files with 93 additions and 82 deletions

View File

@@ -10,10 +10,11 @@ struct Inner {
versions: HashMap<(Uuid, Uuid), Version>,
}
pub(crate) struct InMemoryStorage(Mutex<Inner>);
pub struct InMemoryStorage(Mutex<Inner>);
impl InMemoryStorage {
pub(crate) fn new() -> Self {
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
Self(Mutex::new(Inner {
clients: HashMap::new(),
versions: HashMap::new(),

View File

@@ -1,27 +1,28 @@
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[cfg(test)]
#[cfg(debug_assertions)]
mod inmemory;
#[cfg(test)]
pub(crate) use inmemory::InMemoryStorage;
#[cfg(debug_assertions)]
pub use inmemory::InMemoryStorage;
mod sqlite;
pub(crate) use self::sqlite::SqliteStorage;
pub use self::sqlite::SqliteStorage;
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
pub(crate) struct Client {
pub(crate) latest_version_id: Uuid,
pub struct Client {
pub latest_version_id: Uuid,
}
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
pub(crate) struct Version {
pub(crate) version_id: Uuid,
pub(crate) parent_version_id: Uuid,
pub(crate) history_segment: Vec<u8>,
pub struct Version {
pub version_id: Uuid,
pub parent_version_id: Uuid,
pub history_segment: Vec<u8>,
}
pub(crate) trait StorageTxn {
pub trait StorageTxn {
/// Get information about the given client
fn get_client(&mut self, client_key: Uuid) -> anyhow::Result<Option<Client>>;
@@ -58,7 +59,7 @@ pub(crate) trait StorageTxn {
/// A trait for objects able to act as storage. Most of the interesting behavior is in the
/// [`crate::storage::StorageTxn`] trait.
pub(crate) trait Storage: Send + Sync {
pub trait Storage: Send + Sync {
/// Begin a transaction
fn txn<'a>(&'a self) -> anyhow::Result<Box<dyn StorageTxn + 'a>>;
}

View File

@@ -49,7 +49,7 @@ impl ToSql for Client {
}
/// An on-disk storage backend which uses SQLite
pub(crate) struct SqliteStorage {
pub struct SqliteStorage {
db_file: std::path::PathBuf,
}