diff --git a/src/db.rs b/src/db.rs
index f4cbab3..be95561 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -100,8 +100,8 @@ impl Database {
/// Remove a peer from the database, as represented by the given public
/// key.
- pub fn remove_peer(&self, public_key: &str) -> Result> {
- self.peer_tree.remove(&public_key)
+ pub fn remove_peer(&self, public_key: &str) -> Result<()> {
+ self.peer_tree.remove(&public_key).map(|_| ())
}
/// Get a list of all peers in the peer tree. The public key of each peer
@@ -120,6 +120,8 @@ impl Database {
/// the public key of the peer who authored the post and the key of the
/// post itself, separated by an underscore. The Post is serialized as
/// bincode before the database entry is inserted.
+ ///
+ /// This method can also be used to update an existing database entry.
pub fn add_post(&self, public_key: &str, post: Post) -> Result > {
let post_key = format!("{}_{}", public_key, post.key);
let post_bytes = bincode::serialize(&post).unwrap();
@@ -175,5 +177,15 @@ impl Database {
Ok(post)
}
- // TODO: remove_post
+ /// Remove a single post from the post tree, authored by the given public
+ /// key and defined by the given message ID.
+ pub fn remove_post(&self, public_key: &str, msg_id: &str) -> Result<()> {
+ let post_key = format!("{}_{}", public_key, msg_id);
+
+ // .remove() would ordinarily return the value of the deleted entry
+ // as an Option, returning None if the post_key was not found.
+ // We don't care about the value of the deleted entry so we simply
+ // map the Option to ().
+ self.post_tree.remove(post_key.as_bytes()).map(|_| ())
+ }
}