Skip to content

Commit 0bb9a1c

Browse files
lu-zerododomorandi
andcommitted
Apply the impl Into<String> pattern
Co-authored-by: Edoardo Morandi <morandidodo@gmail.com>
1 parent aaf775c commit 0bb9a1c

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

dht-cache/src/cache.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl Builder {
5757
std::fs::write(pk_path, pem)?;
5858
der
5959
}
60-
Err(e) => Err(e)?,
60+
Err(e) => return Err(e.into()),
6161
}
6262
} else {
6363
generate_rsa_key().1
@@ -110,11 +110,16 @@ impl Cache {
110110
/// Persist a value within the DHT
111111
///
112112
/// It is identified by the topic and uuid value
113-
pub async fn put(&self, topic: &str, uuid: &str, value: &Value) -> Result<(), Error> {
113+
pub async fn put(
114+
&self,
115+
topic: impl Into<String>,
116+
uuid: impl Into<String>,
117+
value: Value,
118+
) -> Result<(), Error> {
114119
let elem = DomoCacheElement {
115-
topic_name: topic.to_string(),
116-
topic_uuid: uuid.to_string(),
117-
value: value.to_owned(),
120+
topic_name: topic.into(),
121+
topic_uuid: uuid.into(),
122+
value,
118123
publication_timestamp: utils::get_epoch_ms(),
119124
publisher_peer_id: self.peer_id.clone(),
120125
..Default::default()
@@ -133,10 +138,14 @@ impl Cache {
133138
///
134139
/// It inserts the deletion entry and the entry value will be marked as deleted and removed
135140
/// from the stored cache.
136-
pub async fn del(&self, topic: &str, uuid: &str) -> Result<(), Error> {
141+
pub async fn del(
142+
&self,
143+
topic: impl Into<String>,
144+
uuid: impl Into<String>,
145+
) -> Result<(), Error> {
137146
let elem = DomoCacheElement {
138-
topic_name: topic.to_string(),
139-
topic_uuid: uuid.to_string(),
147+
topic_name: topic.into(),
148+
topic_uuid: uuid.into(),
140149
publication_timestamp: utils::get_epoch_ms(),
141150
publisher_peer_id: self.peer_id.clone(),
142151
deleted: true,
@@ -317,6 +326,10 @@ pub fn cache_channel(
317326
let mut elem = elem.to_owned();
318327
log::debug!("resending {}", elem.topic_uuid);
319328
elem.republication_timestamp = utils::get_epoch_ms();
329+
330+
// This cannot fail because `cmd` is the sender part of the
331+
// `stream` we are currently reading. In practice, we are
332+
// queueing the commands in order to read them later.
320333
cmd.send(Command::Publish(serde_json::to_value(&elem).unwrap()))
321334
.unwrap();
322335
});

0 commit comments

Comments
 (0)