summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2016-04-17 16:37:09 +0200
committerMatthias Beyer <mail@beyermatthias.de>2016-06-04 15:34:02 +0200
commit735fcc93c585979f952b6dc1c0b6e5310007f2a1 (patch)
treebd0a95dae6d4c1800602b6e68fd910c93de13fef
parent41f0f63c67b899ff8e2ba8d3604364a17de42054 (diff)
downloadimag-735fcc93c585979f952b6dc1c0b6e5310007f2a1.zip
imag-735fcc93c585979f952b6dc1c0b6e5310007f2a1.tar.gz
Add Entry type
-rw-r--r--libimagdiary/src/entry.rs68
1 files changed, 68 insertions, 0 deletions
diff --git a/libimagdiary/src/entry.rs b/libimagdiary/src/entry.rs
new file mode 100644
index 0000000..ca02963
--- /dev/null
+++ b/libimagdiary/src/entry.rs
@@ -0,0 +1,68 @@
+use std::ops::Deref;
+use std::ops::DerefMut;
+
+use libimagstore::store::FileLockEntry;
+use libimagrt::edit::Edit;
+use libimagrt::edit::EditResult;
+use libimagrt::runtime::Runtime;
+
+#[derive(Debug)]
+pub struct Entry<'a>(FileLockEntry<'a>);
+
+impl<'a> Deref for Entry<'a> {
+ type Target = FileLockEntry<'a>;
+
+ fn deref(&self) -> &FileLockEntry<'a> {
+ &self.0
+ }
+
+}
+
+impl<'a> DerefMut for Entry<'a> {
+
+ fn deref_mut(&mut self) -> &mut FileLockEntry<'a> {
+ &mut self.0
+ }
+
+}
+
+impl<'a> Entry<'a> {
+
+ pub fn new(fle: FileLockEntry<'a>) -> Entry<'a> {
+ Entry(fle)
+ }
+
+ /// Get the diary id for this entry.
+ ///
+ /// TODO: calls Option::unwrap() as it assumes that an existing Entry has an ID that is parsable
+ pub fn diary_id(&self) -> DiaryId {
+ DiaryId::from_storeid(&self.0.get_location().clone()).unwrap()
+ }
+
+}
+
+impl<'a> Into<FileLockEntry<'a>> for Entry<'a> {
+
+ fn into(self) -> FileLockEntry<'a> {
+ self.0
+ }
+
+}
+
+impl<'a> From<FileLockEntry<'a>> for Entry<'a> {
+
+ fn from(fle: FileLockEntry<'a>) -> Entry<'a> {
+ Entry::new(fle)
+ }
+
+}
+
+impl<'a> Edit for Entry<'a> {
+
+ fn edit_content(&mut self, rt: &Runtime) -> EditResult<()> {
+ self.0.edit_content(rt)
+ }
+
+}
+
+