Skip to content

Commit 0a87eb6

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

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

dht-cache/src/cache.rs

Lines changed: 12 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,11 @@ 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(&self, topic: impl Into<String>, uuid: impl Into<String>, value: Value) -> Result<(), Error> {
114114
let elem = DomoCacheElement {
115-
topic_name: topic.to_string(),
116-
topic_uuid: uuid.to_string(),
117-
value: value.to_owned(),
115+
topic_name: topic.into(),
116+
topic_uuid: uuid.into(),
117+
value,
118118
publication_timestamp: utils::get_epoch_ms(),
119119
publisher_peer_id: self.peer_id.clone(),
120120
..Default::default()
@@ -133,10 +133,10 @@ impl Cache {
133133
///
134134
/// It inserts the deletion entry and the entry value will be marked as deleted and removed
135135
/// from the stored cache.
136-
pub async fn del(&self, topic: &str, uuid: &str) -> Result<(), Error> {
136+
pub async fn del(&self, topic: impl Into<String>, uuid: impl Into<String>) -> Result<(), Error> {
137137
let elem = DomoCacheElement {
138-
topic_name: topic.to_string(),
139-
topic_uuid: uuid.to_string(),
138+
topic_name: topic.into(),
139+
topic_uuid: uuid.into(),
140140
publication_timestamp: utils::get_epoch_ms(),
141141
publisher_peer_id: self.peer_id.clone(),
142142
deleted: true,
@@ -317,6 +317,10 @@ pub fn cache_channel(
317317
let mut elem = elem.to_owned();
318318
log::debug!("resending {}", elem.topic_uuid);
319319
elem.republication_timestamp = utils::get_epoch_ms();
320+
321+
// This cannot fail because `cmd` is the sender part of the
322+
// `stream` we are currently reading. In practice, we are
323+
// queueing the commands in order to read them later.
320324
cmd.send(Command::Publish(serde_json::to_value(&elem).unwrap()))
321325
.unwrap();
322326
});

0 commit comments

Comments
 (0)