Skip to content

Commit c60e631

Browse files
committed
Apply clippy suggestions
1 parent bf30fbc commit c60e631

File tree

9 files changed

+65
-72
lines changed

9 files changed

+65
-72
lines changed

plutus-ledger-api/src/generators/correct/primitive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub fn arb_natural(n: usize) -> impl Strategy<Value = BigInt> {
5151
/// Helper function to generate a well typed arbitrary natural number
5252
/// Generating `n` vectors of random u32 values, which gives a max bound of u32::MAX ^ n
5353
fn arb_biguint(n: usize) -> impl Strategy<Value = BigUint> {
54-
vec(any::<u32>(), n).prop_map(|value| BigUint::new(value))
54+
vec(any::<u32>(), n).prop_map(BigUint::new)
5555
}
5656

5757
/// Strategy to generate an arbitrary character

plutus-ledger-api/src/plutus_data.rs

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ pub fn case_plutus_data<'a, T>(
175175
pd: &'a PlutusData,
176176
) -> T {
177177
match pd {
178-
PlutusData::Constr(tag, args) => ctor_case(&tag)(&args),
179-
PlutusData::List(args) => list_case(&args),
180-
PlutusData::Integer(i) => int_case(&i),
181-
other => other_case(&other),
178+
PlutusData::Constr(tag, args) => ctor_case(tag)(args),
179+
PlutusData::List(args) => list_case(args),
180+
PlutusData::Integer(i) => int_case(i),
181+
other => other_case(other),
182182
}
183183
}
184184

@@ -252,11 +252,11 @@ impl IsPlutusData for bool {
252252
match plutus_data {
253253
PlutusData::Constr(flag, fields) => match u32::try_from(flag) {
254254
Ok(0) => {
255-
verify_constr_fields(&fields, 0)?;
255+
verify_constr_fields(fields, 0)?;
256256
Ok(false)
257257
}
258258
Ok(1) => {
259-
verify_constr_fields(&fields, 0)?;
259+
verify_constr_fields(fields, 0)?;
260260
Ok(true)
261261
}
262262
_ => Err(PlutusDataError::UnexpectedPlutusInvariant {
@@ -346,11 +346,11 @@ where
346346
match plutus_data {
347347
PlutusData::Constr(flag, fields) => match u32::try_from(flag) {
348348
Ok(0) => {
349-
verify_constr_fields(&fields, 1)?;
349+
verify_constr_fields(fields, 1)?;
350350
Ok(Some(T::from_plutus_data(&fields[0])?))
351351
}
352352
Ok(1) => {
353-
verify_constr_fields(&fields, 0)?;
353+
verify_constr_fields(fields, 0)?;
354354
Ok(None)
355355
}
356356
_ => Err(PlutusDataError::UnexpectedPlutusInvariant {
@@ -383,11 +383,11 @@ where
383383
match plutus_data {
384384
PlutusData::Constr(flag, fields) => match u32::try_from(flag) {
385385
Ok(0) => {
386-
verify_constr_fields(&fields, 1)?;
386+
verify_constr_fields(fields, 1)?;
387387
Ok(Err(E::from_plutus_data(&fields[0])?))
388388
}
389389
Ok(1) => {
390-
verify_constr_fields(&fields, 1)?;
390+
verify_constr_fields(fields, 1)?;
391391
Ok(Ok(T::from_plutus_data(&fields[0])?))
392392
}
393393
_ => Err(PlutusDataError::UnexpectedPlutusInvariant {
@@ -447,7 +447,7 @@ where
447447
fn from_plutus_data(plutus_data: &PlutusData) -> Result<Self, PlutusDataError> {
448448
match plutus_data {
449449
PlutusData::List(vec) => vec
450-
.into_iter()
450+
.iter()
451451
.map(|val| T::from_plutus_data(val))
452452
.collect::<Result<Self, PlutusDataError>>(),
453453
_ => Err(PlutusDataError::UnexpectedPlutusType {
@@ -475,7 +475,7 @@ where
475475
fn from_plutus_data(plutus_data: &PlutusData) -> Result<Self, PlutusDataError> {
476476
match plutus_data {
477477
PlutusData::Map(dict) => dict
478-
.into_iter()
478+
.iter()
479479
.map(|(key, val)| Ok((K::from_plutus_data(key)?, V::from_plutus_data(val)?)))
480480
.collect::<Result<Self, PlutusDataError>>(),
481481
_ => Err(PlutusDataError::UnexpectedPlutusType {
@@ -495,7 +495,7 @@ impl IsPlutusData for () {
495495
match plutus_data {
496496
PlutusData::Constr(flag, fields) => match u32::try_from(flag) {
497497
Ok(0) => {
498-
verify_constr_fields(&fields, 0)?;
498+
verify_constr_fields(fields, 0)?;
499499
Ok(())
500500
}
501501
_ => Err(PlutusDataError::UnexpectedPlutusInvariant {
@@ -538,7 +538,7 @@ where
538538
match plutus_data {
539539
PlutusData::Constr(flag, fields) => match u32::try_from(flag) {
540540
Ok(0) => {
541-
verify_constr_fields(&fields, 2)?;
541+
verify_constr_fields(fields, 2)?;
542542
Ok((
543543
A::from_plutus_data(&fields[0])?,
544544
B::from_plutus_data(&fields[1])?,
@@ -653,9 +653,9 @@ pub fn verify_constr_fields(
653653

654654
/// Given a vector of PlutusData, parse it as an array whose length is known at
655655
/// compile time.
656-
pub fn parse_fixed_len_constr_fields<'a, const LEN: usize>(
657-
v: &'a [PlutusData],
658-
) -> Result<&'a [PlutusData; LEN], PlutusDataError> {
656+
pub fn parse_fixed_len_constr_fields<const LEN: usize>(
657+
v: &[PlutusData],
658+
) -> Result<&[PlutusData; LEN], PlutusDataError> {
659659
v.try_into()
660660
.map_err(|_| PlutusDataError::UnexpectedListLength {
661661
got: v.len(),
@@ -665,9 +665,7 @@ pub fn parse_fixed_len_constr_fields<'a, const LEN: usize>(
665665

666666
/// Given a PlutusData, parse it as PlutusData::Constr and its tag as u32. Return
667667
/// the u32 tag and fields.
668-
pub fn parse_constr<'a>(
669-
data: &'a PlutusData,
670-
) -> Result<(u32, &'a Vec<PlutusData>), PlutusDataError> {
668+
pub fn parse_constr(data: &PlutusData) -> Result<(u32, &Vec<PlutusData>), PlutusDataError> {
671669
match data {
672670
PlutusData::Constr(tag, fields) => u32::try_from(tag)
673671
.map_err(|err| PlutusDataError::UnexpectedPlutusInvariant {
@@ -683,10 +681,10 @@ pub fn parse_constr<'a>(
683681
}
684682

685683
/// Given a PlutusData, parse it as PlutusData::Constr and verify its tag.
686-
pub fn parse_constr_with_tag<'a>(
687-
data: &'a PlutusData,
684+
pub fn parse_constr_with_tag(
685+
data: &PlutusData,
688686
expected_tag: u32,
689-
) -> Result<&'a Vec<PlutusData>, PlutusDataError> {
687+
) -> Result<&Vec<PlutusData>, PlutusDataError> {
690688
let (tag, fields) = parse_constr(data)?;
691689

692690
if tag != expected_tag {

plutus-ledger-api/src/v1/address.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,13 @@ impl IsPlutusData for Credential {
186186
match data {
187187
PlutusData::Constr(flag, fields) => match u32::try_from(flag) {
188188
Ok(0) => {
189-
verify_constr_fields(&fields, 1)?;
189+
verify_constr_fields(fields, 1)?;
190190
Ok(Credential::PubKey(Ed25519PubKeyHash::from_plutus_data(
191191
&fields[0],
192192
)?))
193193
}
194194
Ok(1) => {
195-
verify_constr_fields(&fields, 1)?;
195+
verify_constr_fields(fields, 1)?;
196196
Ok(Credential::Script(ValidatorHash::from_plutus_data(
197197
&fields[0],
198198
)?))
@@ -216,10 +216,10 @@ impl Json for Credential {
216216
fn to_json(&self) -> serde_json::Value {
217217
match self {
218218
Credential::PubKey(pkh) => {
219-
json::json_constructor("PubKeyCredential", &vec![pkh.to_json()])
219+
json::json_constructor("PubKeyCredential", vec![pkh.to_json()])
220220
}
221221
Credential::Script(val_hash) => {
222-
json::json_constructor("ScriptCredential", &vec![val_hash.to_json()])
222+
json::json_constructor("ScriptCredential", vec![val_hash.to_json()])
223223
}
224224
}
225225
}
@@ -319,13 +319,13 @@ impl IsPlutusData for StakingCredential {
319319
match data {
320320
PlutusData::Constr(flag, fields) => match u32::try_from(flag) {
321321
Ok(0) => {
322-
verify_constr_fields(&fields, 1)?;
322+
verify_constr_fields(fields, 1)?;
323323
Ok(StakingCredential::Hash(Credential::from_plutus_data(
324324
&fields[0],
325325
)?))
326326
}
327327
Ok(1) => {
328-
verify_constr_fields(&fields, 3)?;
328+
verify_constr_fields(fields, 3)?;
329329
Ok(StakingCredential::Pointer(ChainPointer {
330330
slot_number: Slot::from_plutus_data(&fields[0])?,
331331
transaction_index: TransactionIndex::from_plutus_data(&fields[1])?,
@@ -351,10 +351,10 @@ impl Json for StakingCredential {
351351
fn to_json(&self) -> serde_json::Value {
352352
match self {
353353
StakingCredential::Hash(pkh) => {
354-
json::json_constructor("StakingHash", &vec![pkh.to_json()])
354+
json::json_constructor("StakingHash", vec![pkh.to_json()])
355355
}
356356
StakingCredential::Pointer(val_hash) => {
357-
json::json_constructor("StakingPtr", &vec![val_hash.to_json()])
357+
json::json_constructor("StakingPtr", vec![val_hash.to_json()])
358358
}
359359
}
360360
}
@@ -377,7 +377,7 @@ impl Json for StakingCredential {
377377
(
378378
"StakingPtr",
379379
Box::new(|ctor_fields| match &ctor_fields[..] {
380-
[val_hash] => Ok(StakingCredential::Pointer(Json::from_json(&val_hash)?)),
380+
[val_hash] => Ok(StakingCredential::Pointer(Json::from_json(val_hash)?)),
381381
_ => Err(Error::UnexpectedArrayLength {
382382
wanted: 1,
383383
got: ctor_fields.len(),

plutus-ledger-api/src/v1/assoc_map.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::plutus_data::{IsPlutusData, PlutusData, PlutusDataError, PlutusType};
1212
// AssocMap //
1313
//////////////
1414

15-
#[derive(Debug, PartialEq, Eq, Clone)]
15+
#[derive(Debug, PartialEq, Eq, Clone, Default)]
1616
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1717
pub struct AssocMap<K, V>(pub Vec<(K, V)>);
1818

@@ -30,9 +30,7 @@ impl<K, V> AssocMap<K, V> {
3030
where
3131
K: PartialEq,
3232
{
33-
let vec = &mut self.0;
34-
35-
let old_value = vec.into_iter().find(|(k, _v)| k == &key);
33+
let old_value = self.0.iter_mut().find(|(k, _v)| k == &key);
3634
match old_value {
3735
None => {
3836
self.0.push((key, value));
@@ -72,8 +70,8 @@ impl<K, V> AssocMap<K, V> {
7270
impl<K: IsPlutusData, V: IsPlutusData> IsPlutusData for AssocMap<K, V> {
7371
fn to_plutus_data(&self) -> PlutusData {
7472
PlutusData::Map(
75-
(&self.0)
76-
.into_iter()
73+
self.0
74+
.iter()
7775
.map(|(k, v)| (k.to_plutus_data(), v.to_plutus_data()))
7876
.collect(),
7977
)
@@ -82,7 +80,7 @@ impl<K: IsPlutusData, V: IsPlutusData> IsPlutusData for AssocMap<K, V> {
8280
fn from_plutus_data(plutus_data: &PlutusData) -> Result<Self, PlutusDataError> {
8381
match plutus_data {
8482
PlutusData::Map(pairs) => pairs
85-
.into_iter()
83+
.iter()
8684
.map(|(k, v)| Ok((K::from_plutus_data(k)?, V::from_plutus_data(v)?)))
8785
.collect::<Result<Vec<(K, V)>, PlutusDataError>>()
8886
.map(Self),
@@ -128,8 +126,8 @@ impl<K: Hash + Eq, V> From<LinkedHashMap<K, V>> for AssocMap<K, V> {
128126
impl<K: Json, V: Json> Json for AssocMap<K, V> {
129127
fn to_json(&self) -> serde_json::Value {
130128
json_array(
131-
(&self.0)
132-
.into_iter()
129+
self.0
130+
.iter()
133131
.map(|(k, v)| json_array(vec![k.to_json(), v.to_json()]))
134132
.collect(),
135133
)

plutus-ledger-api/src/v1/interval.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ where
271271
match data {
272272
PlutusData::Constr(flag, fields) => match u32::try_from(flag) {
273273
Ok(0) => {
274-
verify_constr_fields(&fields, 2)?;
274+
verify_constr_fields(fields, 2)?;
275275
Ok(PlutusInterval {
276276
from: <LowerBound<T>>::from_plutus_data(&fields[0])?,
277277
to: <UpperBound<T>>::from_plutus_data(&fields[1])?,
@@ -321,7 +321,7 @@ where
321321
match data {
322322
PlutusData::Constr(flag, fields) => match u32::try_from(flag) {
323323
Ok(0) => {
324-
verify_constr_fields(&fields, 2)?;
324+
verify_constr_fields(fields, 2)?;
325325
Ok(UpperBound {
326326
bound: <Extended<T>>::from_plutus_data(&fields[0])?,
327327
closed: bool::from_plutus_data(&fields[1])?,
@@ -371,7 +371,7 @@ where
371371
match data {
372372
PlutusData::Constr(flag, fields) => match u32::try_from(flag) {
373373
Ok(0) => {
374-
verify_constr_fields(&fields, 2)?;
374+
verify_constr_fields(fields, 2)?;
375375
Ok(LowerBound {
376376
bound: <Extended<T>>::from_plutus_data(&fields[0])?,
377377
closed: bool::from_plutus_data(&fields[1])?,
@@ -468,17 +468,17 @@ where
468468
match data {
469469
PlutusData::Constr(flag, fields) => match u32::try_from(flag) {
470470
Ok(0) => {
471-
verify_constr_fields(&fields, 0)?;
471+
verify_constr_fields(fields, 0)?;
472472
Ok(Extended::NegInf)
473473
}
474474
Ok(1) => {
475-
verify_constr_fields(&fields, 1)?;
475+
verify_constr_fields(fields, 1)?;
476476
Ok(Extended::Finite(IsPlutusData::from_plutus_data(
477477
&fields[0],
478478
)?))
479479
}
480480
Ok(2) => {
481-
verify_constr_fields(&fields, 0)?;
481+
verify_constr_fields(fields, 0)?;
482482
Ok(Extended::PosInf)
483483
}
484484
_ => Err(PlutusDataError::UnexpectedPlutusInvariant {

plutus-ledger-api/src/v1/transaction.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl IsPlutusData for TransactionInput {
6565
match data {
6666
PlutusData::Constr(flag, fields) => match u32::try_from(flag) {
6767
Ok(0) => {
68-
verify_constr_fields(&fields, 2)?;
68+
verify_constr_fields(fields, 2)?;
6969
Ok(TransactionInput {
7070
transaction_id: TransactionHash::from_plutus_data(&fields[0])?,
7171
index: BigInt::from_plutus_data(&fields[1])?,
@@ -149,7 +149,7 @@ impl IsPlutusData for TransactionHash {
149149
match data {
150150
PlutusData::Constr(flag, fields) => match u32::try_from(flag) {
151151
Ok(0) => {
152-
verify_constr_fields(&fields, 1)?;
152+
verify_constr_fields(fields, 1)?;
153153
Ok(TransactionHash(IsPlutusData::from_plutus_data(&fields[0])?))
154154
}
155155
_ => Err(PlutusDataError::UnexpectedPlutusInvariant {
@@ -212,7 +212,7 @@ impl IsPlutusData for TransactionOutput {
212212
match data {
213213
PlutusData::Constr(flag, fields) => match u32::try_from(flag) {
214214
Ok(0) => {
215-
verify_constr_fields(&fields, 3)?;
215+
verify_constr_fields(fields, 3)?;
216216
Ok(TransactionOutput {
217217
address: Address::from_plutus_data(&fields[0])?,
218218
value: Value::from_plutus_data(&fields[1])?,
@@ -275,10 +275,10 @@ impl TryFrom<POSIXTime> for chrono::DateTime<chrono::Utc> {
275275

276276
fn try_from(posix_time: POSIXTime) -> Result<chrono::DateTime<chrono::Utc>, Self::Error> {
277277
let POSIXTime(millis) = posix_time;
278-
Ok(chrono::DateTime::from_timestamp_millis(
278+
chrono::DateTime::from_timestamp_millis(
279279
<i64>::try_from(millis).map_err(POSIXTimeConversionError::TryFromBigIntError)?,
280280
)
281-
.ok_or(POSIXTimeConversionError::OutOfBoundsError)?)
281+
.ok_or(POSIXTimeConversionError::OutOfBoundsError)
282282
}
283283
}
284284

@@ -316,7 +316,7 @@ impl IsPlutusData for TxInInfo {
316316
match data {
317317
PlutusData::Constr(flag, fields) => match u32::try_from(flag) {
318318
Ok(0) => {
319-
verify_constr_fields(&fields, 2)?;
319+
verify_constr_fields(fields, 2)?;
320320
Ok(TxInInfo {
321321
reference: TransactionInput::from_plutus_data(&fields[0])?,
322322
output: TransactionOutput::from_plutus_data(&fields[1])?,
@@ -479,7 +479,7 @@ impl IsPlutusData for ScriptPurpose {
479479
3 => IsPlutusData::from_plutus_data(field).map(Self::Certifying),
480480
bad_tag => Err(PlutusDataError::UnexpectedPlutusInvariant {
481481
got: bad_tag.to_string(),
482-
wanted: format!("Constr tag to be 0, 1, 2 or 3"),
482+
wanted: "Constr tag to be 0, 1, 2 or 3".to_string(),
483483
}),
484484
}
485485
}

0 commit comments

Comments
 (0)