Skip to content

Commit d7f2714

Browse files
author
Seulgi Kim
committedOct 7, 2018
Implement From instead of Into
1 parent 7f250fc commit d7f2714

File tree

26 files changed

+138
-137
lines changed

26 files changed

+138
-137
lines changed
 

‎core/src/blockchain/extras.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ pub struct ParcelAddress {
178178
pub index: usize,
179179
}
180180

181-
impl Into<ParcelId> for ParcelAddress {
182-
fn into(self) -> ParcelId {
183-
ParcelId::Location(self.block_hash.into(), self.index)
181+
impl From<ParcelAddress> for ParcelId {
182+
fn from(addr: ParcelAddress) -> Self {
183+
ParcelId::Location(addr.block_hash.into(), addr.index)
184184
}
185185
}
186186

‎core/src/scheme/pod_account.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ pub struct PodAccount {
3434
pub regular_key: Option<Public>,
3535
}
3636

37-
impl<'a> Into<Account> for &'a PodAccount {
38-
fn into(self) -> Account {
39-
Account::new_with_key(self.balance, self.nonce, self.regular_key)
37+
impl<'a> From<&'a PodAccount> for Account {
38+
fn from(pod: &'a PodAccount) -> Self {
39+
Account::new_with_key(pod.balance, pod.nonce, pod.regular_key)
4040
}
4141
}
4242

‎core/src/scheme/pod_shard_metadata.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ pub struct PodShardMetadata {
3131
pub worlds: Vec<PodWorld>,
3232
}
3333

34-
impl<'a> Into<ShardMetadata> for &'a PodShardMetadata {
35-
fn into(self) -> ShardMetadata {
36-
assert!(self.worlds.len() <= ::std::u16::MAX as usize);
37-
ShardMetadata::new_with_nonce(self.worlds.len() as u16, self.nonce)
34+
impl<'a> From<&'a PodShardMetadata> for ShardMetadata {
35+
fn from(pod: &'a PodShardMetadata) -> Self {
36+
assert!(pod.worlds.len() <= ::std::u16::MAX as usize);
37+
ShardMetadata::new_with_nonce(pod.worlds.len() as u16, pod.nonce)
3838
}
3939
}
4040

‎core/src/scheme/pod_world.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ pub struct PodWorld {
2828
pub users: Vec<Address>,
2929
}
3030

31-
impl<'a> Into<World> for &'a PodWorld {
32-
fn into(self) -> World {
33-
World::new_with_nonce(self.owners.clone(), self.users.clone(), self.nonce)
31+
impl<'a> From<&'a PodWorld> for World {
32+
fn from(pod: &'a PodWorld) -> Self {
33+
World::new_with_nonce(pod.owners.clone(), pod.users.clone(), pod.nonce)
3434
}
3535
}
3636

‎core/src/scheme/seal.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ pub struct Tendermint {
2828
pub precommits: Vec<H520>,
2929
}
3030

31-
impl Into<Generic> for Tendermint {
32-
fn into(self) -> Generic {
31+
impl From<Tendermint> for Generic {
32+
fn from(tendermint: Tendermint) -> Self {
3333
let mut stream = RlpStream::new_list(3);
34-
stream.append(&self.round).append(&self.proposal).append_list(&self.precommits);
34+
stream.append(&tendermint.round).append(&tendermint.proposal).append_list(&tendermint.precommits);
3535
Generic(stream.out())
3636
}
3737
}
@@ -59,9 +59,9 @@ impl From<cjson::scheme::Seal> for Seal {
5959
}
6060
}
6161

62-
impl Into<Generic> for Seal {
63-
fn into(self) -> Generic {
64-
match self {
62+
impl From<Seal> for Generic {
63+
fn from(seal: Seal) -> Self {
64+
match seal {
6565
Seal::Generic(generic) => generic,
6666
Seal::Tendermint(tender) => tender.into(),
6767
}

‎discovery/src/kademlia/node_id.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ impl KademliaId {
3838
}
3939
}
4040

41-
impl Into<SocketAddr> for KademliaId {
42-
fn into(self) -> SocketAddr {
43-
self.node_id.into_addr()
41+
impl From<KademliaId> for SocketAddr {
42+
fn from(id: KademliaId) -> Self {
43+
id.node_id.into_addr()
4444
}
4545
}
4646

‎json/src/bytes.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ impl Bytes {
3434
}
3535
}
3636

37-
impl Into<Vec<u8>> for Bytes {
38-
fn into(self) -> Vec<u8> {
39-
self.0
37+
impl From<Bytes> for Vec<u8> {
38+
fn from(b: Bytes) -> Self {
39+
b.0
4040
}
4141
}
4242

‎json/src/uint.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,28 @@ use serde::{Deserialize, Deserializer};
2525
#[derive(Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
2626
pub struct Uint(pub U256);
2727

28-
impl Into<U256> for Uint {
29-
fn into(self) -> U256 {
30-
self.0
28+
impl From<Uint> for U256 {
29+
fn from(f: Uint) -> Self {
30+
f.0
3131
}
3232
}
3333

34-
impl Into<u64> for Uint {
35-
fn into(self) -> u64 {
36-
u64::from(self.0)
34+
impl From<Uint> for u64 {
35+
fn from(f: Uint) -> Self {
36+
Self::from(f.0)
3737
}
3838
}
3939

40-
impl Into<usize> for Uint {
41-
fn into(self) -> usize {
40+
impl From<Uint> for usize {
41+
fn from(f: Uint) -> Self {
4242
// TODO: clean it after util conversions refactored.
43-
u64::from(self.0) as usize
43+
u64::from(f.0) as usize
4444
}
4545
}
46-
impl Into<u8> for Uint {
47-
fn into(self) -> u8 {
48-
u64::from(self.0) as u8
46+
47+
impl From<Uint> for u8 {
48+
fn from(f: Uint) -> Self {
49+
u64::from(f.0) as u8
4950
}
5051
}
5152

‎key/src/address.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ impl From<&'static str> for Address {
125125
}
126126
}
127127

128-
impl Into<[u8; 20]> for Address {
129-
fn into(self) -> [u8; 20] {
130-
self.0.into()
128+
impl From<Address> for [u8; 20] {
129+
fn from(a: Address) -> Self {
130+
a.0.into()
131131
}
132132
}
133133

‎key/src/ecdsa.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ impl<'a> From<&'a [u8]> for ECDSASignature {
162162
}
163163
}
164164

165-
impl Into<[u8; 65]> for ECDSASignature {
166-
fn into(self) -> [u8; 65] {
167-
self.0
165+
impl From<ECDSASignature> for [u8; 65] {
166+
fn from(s: ECDSASignature) -> Self {
167+
s.0
168168
}
169169
}
170170

‎key/src/schnorr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ impl From<[u8; 64]> for SchnorrSignature {
108108
}
109109
}
110110

111-
impl Into<[u8; 64]> for SchnorrSignature {
112-
fn into(self) -> [u8; 64] {
113-
self.0
111+
impl From<SchnorrSignature> for [u8; 64] {
112+
fn from(s: SchnorrSignature) -> Self {
113+
s.0
114114
}
115115
}
116116

‎keystore/src/account/cipher.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ impl From<json::Aes128Ctr> for Aes128Ctr {
3434
}
3535
}
3636

37-
impl Into<json::Aes128Ctr> for Aes128Ctr {
38-
fn into(self) -> json::Aes128Ctr {
39-
json::Aes128Ctr {
40-
iv: From::from(self.iv),
37+
impl From<Aes128Ctr> for json::Aes128Ctr {
38+
fn from(aes: Aes128Ctr) -> Self {
39+
Self {
40+
iv: From::from(aes.iv),
4141
}
4242
}
4343
}
@@ -50,9 +50,9 @@ impl From<json::Cipher> for Cipher {
5050
}
5151
}
5252

53-
impl Into<json::Cipher> for Cipher {
54-
fn into(self) -> json::Cipher {
55-
match self {
53+
impl From<Cipher> for json::Cipher {
54+
fn from(cipher: Cipher) -> Self {
55+
match cipher {
5656
Cipher::Aes128Ctr(params) => json::Cipher::Aes128Ctr(params.into()),
5757
}
5858
}

‎keystore/src/account/kdf.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ impl From<json::Prf> for Prf {
5252
}
5353
}
5454

55-
impl Into<json::Prf> for Prf {
56-
fn into(self) -> json::Prf {
57-
match self {
55+
impl From<Prf> for json::Prf {
56+
fn from(prf: Prf) -> Self {
57+
match prf {
5858
Prf::HmacSha256 => json::Prf::HmacSha256,
5959
}
6060
}
@@ -71,13 +71,13 @@ impl From<json::Pbkdf2> for Pbkdf2 {
7171
}
7272
}
7373

74-
impl Into<json::Pbkdf2> for Pbkdf2 {
75-
fn into(self) -> json::Pbkdf2 {
74+
impl From<Pbkdf2> for json::Pbkdf2 {
75+
fn from(p: Pbkdf2) -> Self {
7676
json::Pbkdf2 {
77-
c: self.c,
78-
dklen: self.dklen,
79-
prf: self.prf.into(),
80-
salt: From::from(self.salt),
77+
c: p.c,
78+
dklen: p.dklen,
79+
prf: p.prf.into(),
80+
salt: From::from(p.salt),
8181
}
8282
}
8383
}
@@ -94,14 +94,14 @@ impl From<json::Scrypt> for Scrypt {
9494
}
9595
}
9696

97-
impl Into<json::Scrypt> for Scrypt {
98-
fn into(self) -> json::Scrypt {
99-
json::Scrypt {
100-
dklen: self.dklen,
101-
p: self.p,
102-
n: self.n,
103-
r: self.r,
104-
salt: From::from(self.salt),
97+
impl From<Scrypt> for json::Scrypt {
98+
fn from(s: Scrypt) -> Self {
99+
Self {
100+
dklen: s.dklen,
101+
p: s.p,
102+
n: s.n,
103+
r: s.r,
104+
salt: From::from(s.salt),
105105
}
106106
}
107107
}
@@ -115,9 +115,9 @@ impl From<json::Kdf> for Kdf {
115115
}
116116
}
117117

118-
impl Into<json::Kdf> for Kdf {
119-
fn into(self) -> json::Kdf {
120-
match self {
118+
impl From<Kdf> for json::Kdf {
119+
fn from(kdf: Kdf) -> Self {
120+
match kdf {
121121
Kdf::Pbkdf2(params) => json::Kdf::Pbkdf2(params.into()),
122122
Kdf::Scrypt(params) => json::Kdf::Scrypt(params.into()),
123123
}

‎keystore/src/account/safe_account.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ pub struct SafeAccount {
4040
pub meta: String,
4141
}
4242

43-
impl Into<json::KeyFile> for SafeAccount {
44-
fn into(self) -> json::KeyFile {
45-
json::KeyFile {
46-
id: From::from(self.id),
47-
version: self.version.into(),
48-
address: Some(self.address.into()),
49-
crypto: self.crypto.into(),
50-
name: Some(self.name.into()),
51-
meta: Some(self.meta.into()),
43+
impl From<SafeAccount> for json::KeyFile {
44+
fn from(account: SafeAccount) -> Self {
45+
Self {
46+
id: From::from(account.id),
47+
version: account.version.into(),
48+
address: Some(account.address.into()),
49+
crypto: account.crypto.into(),
50+
name: Some(account.name.into()),
51+
meta: Some(account.meta.into()),
5252
}
5353
}
5454
}

‎keystore/src/account/version.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ impl From<json::Version> for Version {
2929
}
3030
}
3131

32-
impl Into<json::Version> for Version {
33-
fn into(self) -> json::Version {
34-
match self {
32+
impl From<Version> for json::Version {
33+
fn from(version: Version) -> Self {
34+
match version {
3535
Version::V3 => json::Version::V3,
3636
}
3737
}

‎keystore/src/ckeys.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ pub use ckey::*;
1818

1919
use super::json;
2020

21-
impl Into<json::H160> for Address {
22-
fn into(self) -> json::H160 {
23-
let a: [u8; 20] = self.into();
21+
impl From<Address> for json::H160 {
22+
fn from(addr: Address) -> Self {
23+
let a: [u8; 20] = addr.into();
2424
From::from(a)
2525
}
2626
}

‎keystore/src/json/hash.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ macro_rules! impl_hash {
114114
}
115115
}
116116

117-
impl Into<[u8; $size]> for $name {
118-
fn into(self) -> [u8; $size] {
119-
self.0
117+
impl From<$name> for [u8; $size] {
118+
fn from(f: $name) -> Self {
119+
f.0
120120
}
121121
}
122122
};

‎keystore/src/json/id.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ impl From<[u8; 16]> for Uuid {
3232
}
3333
}
3434

35-
impl Into<[u8; 16]> for Uuid {
36-
fn into(self) -> [u8; 16] {
37-
self.0
35+
impl From<Uuid> for [u8; 16] {
36+
fn from(uuid: Uuid) -> Self {
37+
uuid.0
3838
}
3939
}
4040

‎network/src/addr.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,16 @@ pub fn convert_to_node_id(ip: IpAddr, port: u16) -> NodeId {
103103
NodeId::new(ip, port)
104104
}
105105

106-
impl Into<NodeId> for SocketAddr {
107-
fn into(self) -> NodeId {
108-
(&self).into()
106+
impl From<SocketAddr> for NodeId {
107+
fn from(socket: SocketAddr) -> Self {
108+
(&socket).into()
109109
}
110110
}
111111

112-
impl<'a> Into<NodeId> for &'a SocketAddr {
113-
fn into(self) -> NodeId {
114-
let ip = self.addr.ip();
115-
let port = self.addr.port();
112+
impl<'a> From<&'a SocketAddr> for NodeId {
113+
fn from(socket: &'a SocketAddr) -> Self {
114+
let ip = socket.addr.ip();
115+
let port = socket.addr.port();
116116
convert_to_node_id(ip, port)
117117
}
118118
}
@@ -128,15 +128,15 @@ impl From<net::SocketAddr> for SocketAddr {
128128
}
129129
}
130130

131-
impl Into<net::SocketAddr> for SocketAddr {
132-
fn into(self) -> net::SocketAddr {
133-
self.addr
131+
impl From<SocketAddr> for net::SocketAddr {
132+
fn from(socket: SocketAddr) -> Self {
133+
socket.addr
134134
}
135135
}
136136

137-
impl<'a> Into<&'a net::SocketAddr> for &'a SocketAddr {
138-
fn into(self) -> &'a net::SocketAddr {
139-
&self.addr
137+
impl<'a> From<&'a SocketAddr> for &'a net::SocketAddr {
138+
fn from(socket: &'a SocketAddr) -> Self {
139+
&socket.addr
140140
}
141141
}
142142

‎network/src/p2p/stream.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -353,15 +353,15 @@ impl From<TcpStream> for Stream {
353353
}
354354
}
355355

356-
impl Into<TcpStream> for Stream {
357-
fn into(self) -> TcpStream {
358-
self.try_stream.stream
356+
impl From<Stream> for TcpStream {
357+
fn from(stream: Stream) -> Self {
358+
stream.try_stream.stream
359359
}
360360
}
361361

362-
impl Into<Stream> for SignedStream {
363-
fn into(self) -> Stream {
364-
self.stream
362+
impl From<SignedStream> for Stream {
363+
fn from(stream: SignedStream) -> Self {
364+
stream.stream
365365
}
366366
}
367367

‎network/src/session/nonce.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ impl From<u64> for Nonce {
4242
}
4343
}
4444

45-
impl Into<H128> for Nonce {
46-
fn into(self) -> H128 {
47-
self.0
45+
impl From<Nonce> for H128 {
46+
fn from(nonce: Nonce) -> Self {
47+
nonce.0
4848
}
4949
}
5050

51-
impl<'a> Into<&'a H128> for &'a Nonce {
52-
fn into(self) -> &'a H128 {
53-
&self.0
51+
impl<'a> From<&'a Nonce> for &'a H128 {
52+
fn from(nonce: &'a Nonce) -> Self {
53+
&nonce.0
5454
}
5555
}
5656

‎network/src/session_initiator/socket.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ impl From<UdpSocket> for Socket {
155155
}
156156
}
157157

158-
impl Into<UdpSocket> for Socket {
159-
fn into(self) -> UdpSocket {
160-
self.socket
158+
impl From<Socket> for UdpSocket {
159+
fn from(socket: Socket) -> Self {
160+
socket.socket
161161
}
162162
}
163163

‎rpc/src/v1/types/bytes.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ impl From<Vec<u8>> for Bytes {
4242
}
4343
}
4444

45-
impl Into<Vec<u8>> for Bytes {
46-
fn into(self) -> Vec<u8> {
47-
self.0
45+
impl From<Bytes> for Vec<u8> {
46+
fn from(b: Bytes) -> Self {
47+
b.0
4848
}
4949
}
5050

‎state/src/item/address.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ macro_rules! impl_address {
113113
}
114114
}
115115

116-
impl Into<::primitives::H256> for $name {
117-
fn into(self) -> ::primitives::H256 {
118-
self.0
116+
impl From<$name> for ::primitives::H256 {
117+
fn from(a: $name) -> Self {
118+
a.0
119119
}
120120
}
121121

122-
impl<'a> Into<&'a ::primitives::H256> for &'a $name {
123-
fn into(self) -> &'a ::primitives::H256 {
124-
&self.0
122+
impl<'a> From<&'a $name> for &'a ::primitives::H256 {
123+
fn from(a: &'a $name) -> Self {
124+
&a.0
125125
}
126126
}
127127

‎stratum/src/traits.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ impl From<PushMessageError> for Error {
4545
}
4646
}
4747

48-
impl Into<JsonError> for Error {
49-
fn into(self) -> JsonError {
50-
let (code, message) = match self {
48+
impl From<Error> for JsonError {
49+
fn from(err: Error) -> Self {
50+
let (code, message) = match err {
5151
Error::PowHashInvalid => (21, format!("Invalid Pow hash")),
5252
Error::PowInvalid => (22, format!("Invalid the nonce")),
5353
Error::UnauthorizedWorker => (23, format!("Unauthorized worker")),

‎vm/src/executor.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ impl From<bool> for Item {
9494
}
9595
}
9696

97-
impl Into<bool> for Item {
98-
fn into(self) -> bool {
99-
self.as_ref().iter().any(|b| b != &0)
97+
impl From<Item> for bool {
98+
fn from(item: Item) -> Self {
99+
item.as_ref().iter().any(|b| b != &0)
100100
}
101101
}
102102

0 commit comments

Comments
 (0)
Please sign in to comment.