chore(clippy): prefer From to Into

This commit is contained in:
Mirko von Leipzig 2021-08-02 12:15:04 +02:00
parent 7ab0939886
commit 5340a38fa2
3 changed files with 17 additions and 17 deletions

View File

@ -126,11 +126,11 @@ impl Message {
}
}
impl Into<Vec<u8>> for &Message {
fn into(self) -> Vec<u8> {
impl From<&Message> for Vec<u8> {
fn from(val: &Message) -> Self {
let mut proto = bitswap_pb::Message::default();
let mut wantlist = bitswap_pb::message::Wantlist::default();
for (cid, priority) in self.want() {
for (cid, priority) in val.want() {
let entry = bitswap_pb::message::wantlist::Entry {
block: cid.to_bytes(),
priority: *priority,
@ -138,7 +138,7 @@ impl Into<Vec<u8>> for &Message {
};
wantlist.entries.push(entry);
}
for cid in self.cancel() {
for cid in val.cancel() {
let entry = bitswap_pb::message::wantlist::Entry {
block: cid.to_bytes(),
cancel: true,
@ -146,7 +146,7 @@ impl Into<Vec<u8>> for &Message {
};
wantlist.entries.push(entry);
}
for block in self.blocks() {
for block in val.blocks() {
let payload = bitswap_pb::message::Block {
prefix: Prefix::from(block.cid()).to_bytes(),
data: block.data().to_vec(),

View File

@ -340,9 +340,9 @@ impl From<Bytes> for PreformattedJsonMessage {
}
// This direction is required by warp::hyper::Body
impl Into<Bytes> for PreformattedJsonMessage {
fn into(self) -> Bytes {
self.0
impl From<PreformattedJsonMessage> for Bytes {
fn from(val: PreformattedJsonMessage) -> Self {
val.0
}
}

View File

@ -94,26 +94,26 @@ impl PbNode {
}
}
impl Into<Ipld> for PbNode {
fn into(self) -> Ipld {
impl From<PbNode> for Ipld {
fn from(val: PbNode) -> Self {
let mut map = BTreeMap::<String, Ipld>::new();
let links = self
let links = val
.links
.into_iter()
.map(|link| link.into())
.collect::<Vec<Ipld>>();
map.insert("Links".to_string(), links.into());
map.insert("Data".to_string(), self.data.into());
map.insert("Data".to_string(), val.data.into());
map.into()
}
}
impl Into<Ipld> for PbLink {
fn into(self) -> Ipld {
impl From<PbLink> for Ipld {
fn from(val: PbLink) -> Self {
let mut map = BTreeMap::<String, Ipld>::new();
map.insert("Hash".to_string(), self.cid.into());
map.insert("Name".to_string(), self.name.into());
map.insert("Tsize".to_string(), self.size.into());
map.insert("Hash".to_string(), val.cid.into());
map.insert("Name".to_string(), val.name.into());
map.insert("Tsize".to_string(), val.size.into());
map.into()
}
}