From 6013177bfc5b3f3ee6b97abe36900fb22e8632e6 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 25 Jun 2019 18:55:52 +0200 Subject: Add minimal required interfaces --- src/id.rs | 18 ++++++++++++++++++ src/lib.rs | 16 +++++++++------- src/node.rs | 39 +++++++++++++++++++++++++++++++++++++++ src/repository.rs | 27 +++++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 7 deletions(-) create mode 100644 src/id.rs create mode 100644 src/node.rs create mode 100644 src/repository.rs diff --git a/src/id.rs b/src/id.rs new file mode 100644 index 0000000..018ae60 --- /dev/null +++ b/src/id.rs @@ -0,0 +1,18 @@ +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. +// + +use std::fmt::Debug; + +/// An "ID" is an object that can be used to uniquely identify a node in the DAG. +/// +/// In git-speak, this would be a SHA1 hash. +/// +pub trait Id : Clone + Debug + PartialEq + Eq { + + /* empty */ + +} + diff --git a/src/lib.rs b/src/lib.rs index 31e1bb2..bda0996 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,9 @@ -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - assert_eq!(2 + 2, 4); - } -} +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. +// + +pub mod id; +pub mod node; +pub mod repository; diff --git a/src/node.rs b/src/node.rs new file mode 100644 index 0000000..b6a088b --- /dev/null +++ b/src/node.rs @@ -0,0 +1,39 @@ +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. +// + +use std::fmt::Debug; + +use crate::id::Id; + +use futures::future::Future; +use futures::stream::Stream; + +/// A "Node" is an object of the (DA)Graph +/// +/// In git-speak, this would be an "Object". +/// +/// +/// # Equality +/// +/// A node might be compared to another node. In git, for example, equality would be the equality +/// of the nodes ids, because objects are non-mutable. +/// +pub trait Node: Debug + PartialEq + Eq { + type Id: Id; + type NodePayload: Debug; + type Error: Debug; + type Payload: Future; + + /// It should be trivial to get the Id of a Node. + fn id(&self) -> Self::Id; + + /// Fetch the payload of the node. + fn payload(&self) -> Self::Payload; + + /// Fetch the Ids of the parents of this node + fn parent_ids(&self) -> Stream; +} + diff --git a/src/repository.rs b/src/repository.rs new file mode 100644 index 0000000..b4ab3a4 --- /dev/null +++ b/src/repository.rs @@ -0,0 +1,27 @@ +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. +// + +use std::fmt::Debug; + +use crate::node::Node; +use crate::id::Id; + +use futures::future::Future; + +/// +pub trait Repository: Debug { + type Id: Id; + type Error: Debug; + type Node: Node; + + type Get: Future; + + /// It should be trivial to get the Id of a Node. + fn get(id: ID) -> Result + where ID: Id; + +} + -- cgit v1.2.3