Skip to content

Commit ae4a94d

Browse files
committed
fix clippy & primitives - IPFS is now Copy
1 parent 87e2558 commit ae4a94d

File tree

9 files changed

+36
-51
lines changed

9 files changed

+36
-51
lines changed

adview-manager/src/lib.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ pub fn get_unit_html_with_events(
217217
events: vec![Event {
218218
event_type: event_type.to_string(),
219219
publisher: options.publisher_addr,
220-
ad_unit: ad_unit.id.clone(),
221-
ad_slot: options.market_slot.clone(),
220+
ad_unit: ad_unit.id,
221+
ad_slot: options.market_slot,
222222
referrer: "document.referrer".to_string(),
223223
}],
224224
};
@@ -477,12 +477,12 @@ impl Manager {
477477
.units_with_price
478478
.iter()
479479
.filter(|unit_with_price| {
480-
unit_input.ad_unit_id = Some(unit_with_price.unit.id.clone());
480+
unit_input.ad_unit_id = Some(unit_with_price.unit.id);
481481

482482
let mut output = targeting::Output {
483483
show: true,
484484
boost: 1.0,
485-
price: vec![("IMPRESSION".to_string(), unit_with_price.price.clone())]
485+
price: vec![("IMPRESSION".to_string(), unit_with_price.price)]
486486
.into_iter()
487487
.collect(),
488488
};
@@ -519,9 +519,9 @@ impl Manager {
519519

520520
let new_entry = HistoryEntry {
521521
time: Utc::now(),
522-
unit_id: unit_with_price.unit.id.clone(),
522+
unit_id: unit_with_price.unit.id,
523523
campaign_id: *campaign_id,
524-
slot_id: self.options.market_slot.clone(),
524+
slot_id: self.options.market_slot,
525525
};
526526

527527
*self.history.write().await = history
@@ -562,7 +562,7 @@ impl Manager {
562562

563563
Ok(Some(NextAdUnit {
564564
unit: unit_with_price.unit.clone(),
565-
price: unit_with_price.price.clone(),
565+
price: unit_with_price.price,
566566
accepted_referrers: units_for_slot.accepted_referrers,
567567
html,
568568
}))

primitives/src/channel_v5.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub struct Nonce(pub U256);
4242

4343
impl Nonce {
4444
/// In Big-Endian
45-
pub fn to_bytes(&self) -> [u8; 32] {
45+
pub fn to_bytes(self) -> [u8; 32] {
4646
// the impl of From<U256> uses BigEndian
4747
self.0.into()
4848
}

primitives/src/ipfs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const URL_PREFIX: &str = "ipfs://";
77

88
pub use cid::{Cid, Error};
99

10-
#[derive(Hash, Clone, Serialize, Deserialize, Eq, PartialEq)]
10+
#[derive(Hash, Copy, Clone, Serialize, Deserialize, Eq, PartialEq)]
1111
#[serde(try_from = "String", into = "String")]
1212
#[allow(clippy::upper_case_acronyms)]
1313
pub struct IPFS(pub cid::Cid);

primitives/src/supermarket.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ pub enum Finalized {
4343
pub mod units_for_slot {
4444
pub mod response {
4545

46-
use crate::{
47-
targeting::Input,
48-
UnifiedNum, IPFS,
49-
};
46+
use crate::{targeting::Input, UnifiedNum, IPFS};
5047
use serde::{Deserialize, Serialize};
5148
use url::Url;
5249

@@ -88,7 +85,7 @@ pub mod units_for_slot {
8885
impl From<&crate::AdUnit> for AdUnit {
8986
fn from(ad_unit: &crate::AdUnit) -> Self {
9087
Self {
91-
id: ad_unit.ipfs.clone(),
88+
id: ad_unit.ipfs,
9289
media_url: ad_unit.media_url.clone(),
9390
media_mime: ad_unit.media_mime.clone(),
9491
target_url: ad_unit.target_url.clone(),

primitives/src/targeting.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl Output {
5050
.price
5151
.get(price_key.trim_start_matches("price."))
5252
.ok_or(Error::UnknownVariable)?;
53-
Ok(Value::UnifiedNum(price.clone()))
53+
Ok(Value::UnifiedNum(*price))
5454
}
5555
_ => Err(Error::UnknownVariable),
5656
}

primitives/src/targeting/input.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,10 @@ pub mod campaign {
282282
}) => (*campaign_seconds_duration).into(),
283283
})),
284284
field::Campaign::CampaignBudget => Some(Value::UnifiedNum(match self {
285-
Get::Getter(FullCampaign { campaign, .. }) => campaign.budget.clone(),
285+
Get::Getter(FullCampaign { campaign, .. }) => campaign.budget,
286286
Get::Value(Values {
287287
campaign_budget, ..
288-
}) => campaign_budget.clone(),
288+
}) => *campaign_budget,
289289
})),
290290
field::Campaign::EventMinPrice => match self {
291291
Get::Getter(FullCampaign {
@@ -296,7 +296,7 @@ pub mod campaign {
296296
)),
297297
Get::Value(Values {
298298
event_min_price, ..
299-
}) => event_min_price.clone().map(Value::UnifiedNum),
299+
}) => event_min_price.map(Value::UnifiedNum),
300300
},
301301
field::Campaign::EventMaxPrice => match self {
302302
Get::Getter(FullCampaign {
@@ -307,7 +307,7 @@ pub mod campaign {
307307
)),
308308
Get::Value(Values {
309309
event_max_price, ..
310-
}) => event_max_price.clone().map(Value::UnifiedNum),
310+
}) => event_max_price.map(Value::UnifiedNum),
311311
},
312312
}
313313
}

primitives/src/unified_num.rs

+13-16
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,18 @@ use std::{
2828
/// use primitives::UnifiedNum;
2929
/// use serde_json::Value;
3030
///
31-
/// fn main() {
32-
/// let unified_num = UnifiedNum::from(42_999_987_654_321);
33-
///
34-
/// // Printing the unified num will show the value and the decimal point with precision of `UnifiedNum::PRECISION` (i.e. `8`) numbers after the decimal point
35-
/// assert_eq!("42999987654321", &unified_num.to_string());
31+
/// let unified_num = UnifiedNum::from(42_999_987_654_321);
3632
///
37-
/// assert_eq!("429999.87654321", &unified_num.to_float_string());
33+
/// // Printing the unified num will show the value and the decimal point with precision of `UnifiedNum::PRECISION` (i.e. `8`) numbers after the decimal point
34+
/// assert_eq!("42999987654321", &unified_num.to_string());
3835
///
39-
/// // Printing the Debug of unified num will show the value and the decimal point with precision of `UnifiedNum::PRECISION` (i.e. `8`) numbers after the decimal point
40-
/// assert_eq!("UnifiedNum(429999.87654321)".to_string(), format!("{:?}", &unified_num));
36+
/// assert_eq!("429999.87654321", &unified_num.to_float_string());
4137
///
42-
/// // JSON Serializing and Deserializing the `UnifiedNum` yields a string without any decimal points
43-
/// assert_eq!(Value::String("42999987654321".to_string()), serde_json::to_value(unified_num).unwrap());
44-
/// }
38+
/// // Printing the Debug of unified num will show the value and the decimal point with precision of `UnifiedNum::PRECISION` (i.e. `8`) numbers after the decimal point
39+
/// assert_eq!("UnifiedNum(429999.87654321)".to_string(), format!("{:?}", &unified_num));
40+
///
41+
/// // JSON Serializing and Deserializing the `UnifiedNum` yields a string without any decimal points
42+
/// assert_eq!(Value::String("42999987654321".to_string()), serde_json::to_value(unified_num).unwrap());
4543
/// ```
4644
#[derive(
4745
Clone,
@@ -79,7 +77,6 @@ impl TryFrom<String> for UnifiedNum {
7977
}
8078
}
8179

82-
8380
impl UnifiedNum {
8481
pub const PRECISION: u8 = 8;
8582
pub const DEBUG_DELIMITER: char = '.';
@@ -92,11 +89,11 @@ impl UnifiedNum {
9289
Self(value)
9390
}
9491

95-
pub const fn to_u64(&self) -> u64 {
92+
pub const fn to_u64(self) -> u64 {
9693
self.0
9794
}
9895

99-
pub fn to_bignum(&self) -> BigNum {
96+
pub fn to_bignum(self) -> BigNum {
10097
BigNum::from(self.0)
10198
}
10299

@@ -121,7 +118,7 @@ impl UnifiedNum {
121118
}
122119

123120
/// Transform the UnifiedNum precision 8 to a new precision
124-
pub fn to_precision(&self, precision: u8) -> BigNum {
121+
pub fn to_precision(self, precision: u8) -> BigNum {
125122
let inner = BigNum::from(self.0);
126123
match precision.cmp(&Self::PRECISION) {
127124
Ordering::Equal => inner,
@@ -130,7 +127,7 @@ impl UnifiedNum {
130127
}
131128
}
132129

133-
pub fn to_float_string(&self) -> String {
130+
pub fn to_float_string(self) -> String {
134131
let mut string_value = self.0.to_string();
135132
let value_length = string_value.len();
136133
let precision: usize = Self::PRECISION.into();

primitives/src/validator.rs

+1-15
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,13 @@ impl ValidatorId {
2222
self.0.as_bytes()
2323
}
2424

25-
pub fn to_address(&self) -> Address {
25+
pub fn to_address(self) -> Address {
2626
self.0
2727
}
2828

2929
pub fn inner(&self) -> &[u8; 20] {
3030
&self.0.as_bytes()
3131
}
32-
33-
/// To Hex non-`0x` prefixed string without **Checksum**ing the string
34-
/// For backwards compatibility
35-
/// TODO: Remove once we change all places this method is used at
36-
pub fn to_hex_non_prefix_string(&self) -> String {
37-
self.0.to_hex()
38-
}
39-
40-
/// To Hex `0x` prefixed string **without** __Checksum__ing the string
41-
/// For backwards compatibility
42-
/// TODO: Remove once we change all places this method is used at
43-
pub fn to_hex_prefix_string(&self) -> String {
44-
self.0.to_hex_prefixed()
45-
}
4632
}
4733

4834
impl ToETHChecksum for ValidatorId {}

sentry/src/payout.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
use crate::Session;
22
use chrono::Utc;
3-
use primitives::{Address, BigNum, Campaign, UnifiedNum, sentry::Event, targeting::Input, targeting::{eval_with_callback, get_pricing_bounds, input, Error, Output}};
3+
use primitives::{
4+
sentry::Event,
5+
targeting::Input,
6+
targeting::{eval_with_callback, get_pricing_bounds, input, Error, Output},
7+
Address, Campaign, UnifiedNum,
8+
};
49
use slog::{error, Logger};
510
use std::cmp::{max, min};
611

0 commit comments

Comments
 (0)