Skip to content

Commit

Permalink
refactor: replace a From<Vec<Foo>> by FromIterator<Foo>
Browse files Browse the repository at this point in the history
This is more versatile, makes the construction more visible, and can be used with collect.
  • Loading branch information
huitseeker committed Apr 30, 2022
1 parent 26fce70 commit 10ef071
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions faucet/src/faucet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ pub trait Faucet {
) -> Result<FaucetReceipt, FaucetError>;
}

impl From<Vec<Object>> for FaucetReceipt {
fn from(v: Vec<Object>) -> Self {
Self {
sent: v.iter().map(|c| c.into()).collect(),
impl<'a> FromIterator<&'a Object> for FaucetReceipt {
fn from_iter<T: IntoIterator<Item = &'a Object>>(iter: T) -> Self {
FaucetReceipt {
sent: iter.into_iter().map(|o| o.into()).collect(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion faucet/src/faucet/simple_faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,6 @@ impl Faucet for SimpleFaucet {
let coins = self.get_coins(amounts).await?;
let coin_ids = coins.iter().map(|c| c.id()).collect::<Vec<ObjectID>>();
self.transfer_coins(&coin_ids, recipient).await?;
Ok(coins.into())
Ok(coins.iter().by_ref().collect())
}
}

0 comments on commit 10ef071

Please sign in to comment.