Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
larry0x committed May 19, 2022
1 parent e5be8aa commit 3541ed9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl FromStr for AssetUnchecked {
type Err = StdError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let words: Vec<&str> = s.split(":").collect();
let words: Vec<&str> = s.split(':').collect();
if words.len() != 3 {
return Err(StdError::generic_err(
format!("invalid asset format `{}`; must be in format `native:{{denom}}:{{amount}}` or `cw20:{{contract_addr}}:{{amount}}`", s)
Expand Down Expand Up @@ -173,7 +173,7 @@ impl TryFrom<Asset> for Coin {
amount: asset.amount,
}),
AssetInfo::Cw20(_) => Err(StdError::generic_err(
format!("cannot cast asset {} into cosmwasm_std::Coin", asset.to_string())
format!("cannot cast asset {} into cosmwasm_std::Coin", asset)
)),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/asset_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl FromStr for AssetInfoUnchecked {
type Err = StdError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let words: Vec<&str> = s.split(":").collect();
let words: Vec<&str> = s.split(':').collect();
if words.len() != 2 {
return Err(StdError::generic_err(
format!("invalid asset info format `{}`; must be in format `native:{{denom}}` or `cw20:{{contract_addr}}`", s)
Expand Down
24 changes: 22 additions & 2 deletions src/asset_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ impl FromStr for AssetListUnchecked {
type Err = StdError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
if s.len() == 0 {
if s.is_empty() {
return Ok(Self(vec![]));
}

Ok(Self(
s
.split(",")
.split(',')
.collect::<Vec<&str>>()
.iter()
.map(|s| AssetUnchecked::from_str(s))
Expand Down Expand Up @@ -190,10 +190,30 @@ impl AssetList {
///
/// let len = list.len(); // should be two
/// ```
// NOTE: I do have `is_empty` implemented, but clippy still throws a warning saying I don't have
// it. Must be a clippy bug...
#[allow(clippy::len_without_is_empty)]
pub fn len(&self) -> usize {
self.0.len()
}

/// Return whether the asset list is empty
///
/// ```rust
/// use cw_asset::{Asset, AssetList};
///
/// let mut list = AssetList::from(vec![
/// Asset::native("uluna", 12345u128),
/// ]);
/// let is_empty = list.is_empty(); // should be `false`
///
/// list.deduct(&Asset::native("uluna", 12345u128)).unwrap();
/// let is_empty = list.is_empty(); // should be `true`
/// ```
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}

/// Find an asset in the list that matches the provided asset info
///
/// Return `Some(&asset)` if found, where `&asset` is a reference to the asset found; `None` if
Expand Down

0 comments on commit 3541ed9

Please sign in to comment.