use a trait object for the server, for dynamic dispatch

This commit is contained in:
Dustin J. Mitchell
2020-11-26 10:52:28 -05:00
parent 087333a227
commit a5c06008b3
5 changed files with 36 additions and 15 deletions

View File

@@ -1,34 +0,0 @@
use crate::types::{AddVersionResult, ClientId, GetVersionResult, HistorySegment, VersionId};
use failure::Fallible;
use taskchampion::Uuid;
/// The sync server's implementation; HTTP API method call through to methods on a single
/// instance of this type.
pub(crate) struct SyncServer {}
impl SyncServer {
pub(crate) fn new() -> Self {
Self {}
}
pub(crate) fn get_child_version(
&self,
_client_id: ClientId,
parent_version_id: VersionId,
) -> Fallible<Option<GetVersionResult>> {
Ok(Some(GetVersionResult {
version_id: Uuid::new_v4(),
parent_version_id,
history_segment: b"abcd".to_vec(),
}))
}
pub(crate) fn add_version(
&self,
_client_id: ClientId,
_parent_version_id: VersionId,
_history_segment: &HistorySegment,
) -> Fallible<AddVersionResult> {
Ok(AddVersionResult::Ok(Uuid::new_v4()))
}
}