Skip to content

Commit ebd6f37

Browse files
authored
chore: use derives instead manual impl for trivial derefs (#6429)
1 parent bf7c644 commit ebd6f37

File tree

8 files changed

+91
-142
lines changed

8 files changed

+91
-142
lines changed

src/rpc/methods/eth/types.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub const METHOD_GET_STORAGE_AT: u64 = 5;
2828
JsonSchema,
2929
derive_more::From,
3030
derive_more::Into,
31+
derive_more::Deref,
3132
GetSize,
3233
)]
3334
pub struct EthBytes(
@@ -59,14 +60,6 @@ impl FromStr for EthBytes {
5960
}
6061
}
6162

62-
impl Deref for EthBytes {
63-
type Target = Vec<u8>;
64-
65-
fn deref(&self) -> &Self::Target {
66-
&self.0
67-
}
68-
}
69-
7063
#[derive(Debug, Deserialize, Serialize)]
7164
pub struct GetBytecodeReturn(pub Option<Cid>);
7265

src/shim/address.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
// Copyright 2019-2026 ChainSafe Systems
22
// SPDX-License-Identifier: Apache-2.0, MIT
33

4-
use std::{
5-
fmt::Display,
6-
ops::{Deref, DerefMut},
7-
str::FromStr,
8-
};
4+
use std::{fmt::Display, str::FromStr};
95

106
use data_encoding::Encoding;
117
use data_encoding_macro::new_encoding;
@@ -113,7 +109,20 @@ mod network_guard_impl {
113109
/// parse both versions and discard the prefix. See also [`StrictAddress`].
114110
///
115111
/// For more information, see: <https://spec.filecoin.io/appendix/address/>
116-
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
112+
#[derive(
113+
Copy,
114+
Clone,
115+
Debug,
116+
Hash,
117+
PartialEq,
118+
Eq,
119+
PartialOrd,
120+
Ord,
121+
Serialize,
122+
Deserialize,
123+
derive_more::Deref,
124+
derive_more::DerefMut,
125+
)]
117126
#[serde(transparent)]
118127
#[cfg_attr(test, derive(derive_quickcheck_arbitrary::Arbitrary))]
119128
pub struct Address(Address_latest);
@@ -247,19 +256,6 @@ impl Display for Address {
247256
}
248257
}
249258

250-
impl Deref for Address {
251-
type Target = Address_latest;
252-
fn deref(&self) -> &Self::Target {
253-
&self.0
254-
}
255-
}
256-
257-
impl DerefMut for Address {
258-
fn deref_mut(&mut self) -> &mut Self::Target {
259-
&mut self.0
260-
}
261-
}
262-
263259
impl GetSize for Address {
264260
fn get_heap_size(&self) -> usize {
265261
0 // all variants of the internal payload are stack-allocated

src/shim/bigint.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
11
// Copyright 2019-2026 ChainSafe Systems
22
// SPDX-License-Identifier: Apache-2.0, MIT
33

4-
use std::ops::{Deref, DerefMut};
5-
64
use super::fvm_shared_latest::bigint::bigint_ser;
75
use serde::{Deserialize, Serialize};
86

9-
#[derive(Default, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
7+
#[derive(
8+
Default,
9+
Clone,
10+
Debug,
11+
PartialEq,
12+
Eq,
13+
Serialize,
14+
Deserialize,
15+
derive_more::Deref,
16+
derive_more::DerefMut,
17+
)]
1018
#[serde(transparent)]
1119
pub struct BigInt(#[serde(with = "bigint_ser")] num_bigint::BigInt);
1220

13-
impl Deref for BigInt {
14-
type Target = num_bigint::BigInt;
15-
fn deref(&self) -> &Self::Target {
16-
&self.0
17-
}
18-
}
19-
20-
impl DerefMut for BigInt {
21-
fn deref_mut(&mut self) -> &mut Self::Target {
22-
&mut self.0
23-
}
24-
}
25-
2621
impl From<num_bigint::BigInt> for BigInt {
2722
fn from(other: num_bigint::BigInt) -> Self {
2823
BigInt(other)

src/shim/econ.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize};
1414
use static_assertions::const_assert_eq;
1515
use std::{
1616
fmt,
17-
ops::{Add, AddAssign, Deref, DerefMut, Div, Mul, MulAssign, Neg, Rem, Sub, SubAssign},
17+
ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Rem, Sub, SubAssign},
1818
sync::LazyLock,
1919
};
2020

@@ -25,7 +25,19 @@ const_assert_eq!(TOTAL_FILECOIN_BASE, fvm_shared2::TOTAL_FILECOIN_BASE);
2525
pub static TOTAL_FILECOIN: LazyLock<TokenAmount> =
2626
LazyLock::new(|| TokenAmount::from_whole(TOTAL_FILECOIN_BASE));
2727

28-
#[derive(Clone, PartialEq, Eq, Ord, PartialOrd, Hash, Serialize, Deserialize, Default)]
28+
#[derive(
29+
Clone,
30+
PartialEq,
31+
Eq,
32+
Ord,
33+
PartialOrd,
34+
Hash,
35+
Serialize,
36+
Deserialize,
37+
Default,
38+
derive_more::Deref,
39+
derive_more::DerefMut,
40+
)]
2941
#[serde(transparent)]
3042
pub struct TokenAmount(TokenAmount_latest);
3143

@@ -99,20 +111,6 @@ impl Neg for &TokenAmount {
99111
}
100112
}
101113

102-
impl Deref for TokenAmount {
103-
type Target = TokenAmount_latest;
104-
105-
fn deref(&self) -> &Self::Target {
106-
&self.0
107-
}
108-
}
109-
110-
impl DerefMut for TokenAmount {
111-
fn deref_mut(&mut self) -> &mut Self::Target {
112-
&mut self.0
113-
}
114-
}
115-
116114
impl std::fmt::Display for TokenAmount {
117115
// This trait requires `fmt` with this exact signature.
118116
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {

src/shim/randomness.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright 2019-2026 ChainSafe Systems
22
// SPDX-License-Identifier: Apache-2.0, MIT
33

4-
use std::ops::{Deref, DerefMut};
5-
64
use super::fvm_shared_latest::randomness::Randomness as Randomness_latest;
75
use fvm_shared2::randomness::Randomness as Randomness_v2;
86
use fvm_shared3::randomness::Randomness as Randomness_v3;
@@ -31,7 +29,17 @@ use serde::{Deserialize, Serialize};
3129
/// assert_eq!(fvm3_rand, rand_shim.clone().into());
3230
/// assert_eq!(fvm2_rand, rand_shim.into());
3331
/// ```
34-
#[derive(PartialEq, Eq, Default, Clone, Debug, Deserialize, Serialize)]
32+
#[derive(
33+
PartialEq,
34+
Eq,
35+
Default,
36+
Clone,
37+
Debug,
38+
Deserialize,
39+
Serialize,
40+
derive_more::Deref,
41+
derive_more::DerefMut,
42+
)]
3543
#[serde(transparent)]
3644
pub struct Randomness(Randomness_latest);
3745

@@ -41,19 +49,6 @@ impl Randomness {
4149
}
4250
}
4351

44-
impl Deref for Randomness {
45-
type Target = Randomness_latest;
46-
fn deref(&self) -> &Self::Target {
47-
&self.0
48-
}
49-
}
50-
51-
impl DerefMut for Randomness {
52-
fn deref_mut(&mut self) -> &mut Self::Target {
53-
&mut self.0
54-
}
55-
}
56-
5752
impl From<Randomness_v4> for Randomness {
5853
fn from(other: Randomness_v4) -> Self {
5954
Randomness(other)

src/shim/sector.rs

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use get_size2::GetSize;
2323
use num_derive::FromPrimitive;
2424
use serde::{Deserialize, Serialize};
2525
use std::hash::{Hash, Hasher};
26-
use std::ops::Deref;
2726

2827
pub type SectorNumber = fvm_shared4::sector::SectorNumber;
2928

@@ -48,7 +47,9 @@ pub type SectorNumber = fvm_shared4::sector::SectorNumber;
4847
/// assert_eq!(fvm3_proof, proof_shim.into());
4948
/// assert_eq!(fvm2_proof, proof_shim.into());
5049
/// ```
51-
#[derive(serde::Serialize, serde::Deserialize, Clone, Copy, Eq, PartialEq, Debug)]
50+
#[derive(
51+
serde::Serialize, serde::Deserialize, Clone, Copy, Eq, PartialEq, Debug, derive_more::Deref,
52+
)]
5253
pub struct RegisteredSealProof(RegisteredSealProofV4);
5354

5455
impl RegisteredSealProof {
@@ -97,13 +98,6 @@ impl RegisteredSealProof {
9798
}
9899
}
99100

100-
impl Deref for RegisteredSealProof {
101-
type Target = RegisteredSealProofV4;
102-
fn deref(&self) -> &Self::Target {
103-
&self.0
104-
}
105-
}
106-
107101
impl From<i64> for RegisteredSealProof {
108102
fn from(value: i64) -> Self {
109103
RegisteredSealProof(RegisteredSealProofV4::from(value))
@@ -151,7 +145,15 @@ impl quickcheck::Arbitrary for RegisteredSealProof {
151145
/// Represents a shim over `SectorInfo` from `fvm_shared` with convenience
152146
/// methods to convert to an older version of the type
153147
#[derive(
154-
Eq, PartialEq, Debug, Clone, derive_more::From, derive_more::Into, Serialize, Deserialize,
148+
Eq,
149+
PartialEq,
150+
Debug,
151+
Clone,
152+
derive_more::From,
153+
derive_more::Into,
154+
derive_more::Deref,
155+
Serialize,
156+
Deserialize,
155157
)]
156158
pub struct SectorInfo(SectorInfoV4);
157159

@@ -180,13 +182,6 @@ impl SectorInfo {
180182
}
181183
}
182184

183-
impl Deref for SectorInfo {
184-
type Target = SectorInfoV4;
185-
fn deref(&self) -> &Self::Target {
186-
&self.0
187-
}
188-
}
189-
190185
impl From<SectorInfo> for SectorInfoV2 {
191186
fn from(value: SectorInfo) -> SectorInfoV2 {
192187
SectorInfoV2 {
@@ -226,7 +221,16 @@ impl quickcheck::Arbitrary for ExtendedSectorInfo {
226221
}
227222
}
228223

229-
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, Eq, PartialEq, derive_more::Into)]
224+
#[derive(
225+
serde::Serialize,
226+
serde::Deserialize,
227+
Clone,
228+
Debug,
229+
Eq,
230+
PartialEq,
231+
derive_more::Into,
232+
derive_more::Deref,
233+
)]
230234
pub struct RegisteredPoStProof(RegisteredPoStProofV4);
231235

232236
#[cfg(test)]
@@ -236,13 +240,6 @@ impl quickcheck::Arbitrary for RegisteredPoStProof {
236240
}
237241
}
238242

239-
impl Deref for RegisteredPoStProof {
240-
type Target = RegisteredPoStProofV4;
241-
fn deref(&self) -> &Self::Target {
242-
&self.0
243-
}
244-
}
245-
246243
impl TryFrom<RegisteredPoStProof> for fil_actors_shared::filecoin_proofs_api::RegisteredPoStProof {
247244
type Error = anyhow::Error;
248245

@@ -342,6 +339,7 @@ sector_size_conversion!(SectorSizeV2, SectorSizeV3, SectorSizeV4);
342339
PartialEq,
343340
derive_more::From,
344341
derive_more::Into,
342+
derive_more::Deref,
345343
Eq,
346344
)]
347345
#[cfg_attr(test, derive(derive_quickcheck_arbitrary::Arbitrary))]
@@ -367,14 +365,6 @@ impl PoStProof {
367365
}
368366
}
369367

370-
impl Deref for PoStProof {
371-
type Target = PoStProofV4;
372-
373-
fn deref(&self) -> &Self::Target {
374-
&self.0
375-
}
376-
}
377-
378368
impl From<PoStProofV2> for PoStProof {
379369
fn from(value: PoStProofV2) -> PoStProof {
380370
PoStProof(PoStProofV4 {

src/shim/state_tree.rs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// Copyright 2019-2026 ChainSafe Systems
22
// SPDX-License-Identifier: Apache-2.0, MIT
3-
use std::{
4-
ops::{Deref, DerefMut},
5-
sync::Arc,
6-
};
3+
use std::sync::Arc;
74

85
use crate::{
96
networks::{ACTOR_BUNDLES_METADATA, ActorBundleMetadata},
@@ -413,7 +410,9 @@ where
413410
/// assert_eq!(fvm3_actor_state, state_shim.clone().into());
414411
/// assert_eq!(fvm2_actor_state, state_shim.into());
415412
/// ```
416-
#[derive(PartialEq, Eq, Clone, Debug, Serialize, Deserialize)]
413+
#[derive(
414+
PartialEq, Eq, Clone, Debug, Serialize, Deserialize, derive_more::Deref, derive_more::DerefMut,
415+
)]
417416
#[serde(transparent)]
418417
#[cfg_attr(test, derive(derive_quickcheck_arbitrary::Arbitrary))]
419418
pub struct ActorState(ActorState_latest);
@@ -443,20 +442,6 @@ impl ActorState {
443442
}
444443
}
445444

446-
impl Deref for ActorState {
447-
type Target = ActorState_latest;
448-
449-
fn deref(&self) -> &Self::Target {
450-
&self.0
451-
}
452-
}
453-
454-
impl DerefMut for ActorState {
455-
fn deref_mut(&mut self) -> &mut Self::Target {
456-
&mut self.0
457-
}
458-
}
459-
460445
impl From<&ActorStateV2> for ActorState {
461446
fn from(value: &ActorStateV2) -> Self {
462447
Self(ActorState_latest {

0 commit comments

Comments
 (0)