Skip to content

Commit 6bba7dd

Browse files
author
ChallengeDev210
committed
Merge rust-bitcoin/rust-bitcoin#800: Use fn name to_ instead of into_
1511738 Use fn name to_ instead of into_ (Tobin Harding) Pull request description: Rust convention is to use `to_` for conversion methods that convert from an owned type to an owned `Copy` type. `into_` is for owned to owned non-`Copy` types. Re-name conversion methods that use `into_` for `Copy` types to use `to_`, no need to deprecate these ones because they are unreleased. **Note to maintainers** This is similar in concept to #798 but only touches new code introduced in this release. Has been labelled 'RC fix' for that reason. Please feel free to remove the label if you disagree. From the docs: https://rust-lang.github.io/api-guidelines/naming.html <h2><a class="header" href="https://rust-lang.github.io/api-guidelines/naming.html#ad-hoc-conversions-follow-as_-to_-into_-conventions-c-conv" id="ad-hoc-conversions-follow-as_-to_-into_-conventions-c-conv">Ad-hoc conversions follow <code>as_</code>, <code>to_</code>, <code>into_</code> conventions (C-CONV)</a></h2> <p>Conversions should be provided as methods, with names prefixed as follows:</p> Prefix | Cost | Ownership -- | -- | -- as_ | Free | borrowed -> borrowed to_ | Expensive | borrowed -> borrowed | | | borrowed -> owned (non-Copy types) | | | owned -> owned (Copy types) into_ | Variable | owned -> owned (non-Copy types) ACKs for top commit: Kixunil: ACK 1511738 apoelstra: ACK 1511738 sanket1729: ACK 1511738 Tree-SHA512: 4bb97e4fb78beda0fd1ec9482d24ef0f4ade6d3689f5c1bcf2208fa2df3195962522fa5d5ac700e6d4d5ff2096a20b2a0ad51784909a3c12405762aa08d1ced2
2 parents 449d9b2 + e826cc1 commit 6bba7dd

File tree

5 files changed

+14
-14
lines changed

5 files changed

+14
-14
lines changed

src/util/address.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ impl Payload {
465465
let (output_key, _parity) = internal_key.tap_tweak(secp, merkle_root);
466466
Payload::WitnessProgram {
467467
version: WitnessVersion::V1,
468-
program: output_key.into_inner().serialize().to_vec(),
468+
program: output_key.to_inner().serialize().to_vec(),
469469
}
470470
}
471471

src/util/psbt/serialize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl Serialize for (Script, LeafVersion) {
264264
fn serialize(&self) -> Vec<u8> {
265265
let mut buf = Vec::with_capacity(self.0.len() + 1);
266266
buf.extend(self.0.as_bytes());
267-
buf.push(self.1.into_consensus());
267+
buf.push(self.1.to_consensus());
268268
buf
269269
}
270270
}
@@ -312,7 +312,7 @@ impl Serialize for TapTree {
312312
// TaprootMerkleBranch can only have len atmost 128(TAPROOT_CONTROL_MAX_NODE_COUNT).
313313
// safe to cast from usize to u8
314314
buf.push(leaf_info.merkle_branch.as_inner().len() as u8);
315-
buf.push(leaf_info.ver.into_consensus());
315+
buf.push(leaf_info.ver.to_consensus());
316316
leaf_info.script.consensus_encode(&mut buf).expect("Vecs dont err");
317317
}
318318
buf

src/util/schnorr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl TweakedPublicKey {
161161
}
162162

163163
/// Returns the underlying public key.
164-
pub fn into_inner(self) -> ::XOnlyPublicKey {
164+
pub fn to_inner(self) -> ::XOnlyPublicKey {
165165
self.0
166166
}
167167

src/util/sighash.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl<'s> ScriptPath<'s> {
235235
pub fn leaf_hash(&self) -> TapLeafHash {
236236
let mut enc = TapLeafHash::engine();
237237

238-
self.leaf_version.into_consensus().consensus_encode(&mut enc).expect("Writing to hash enging should never fail");
238+
self.leaf_version.to_consensus().consensus_encode(&mut enc).expect("Writing to hash enging should never fail");
239239
self.script.consensus_encode(&mut enc).expect("Writing to hash enging should never fail");
240240

241241
TapLeafHash::from_engine(enc)

src/util/taproot.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl TapLeafHash {
120120
/// function to compute leaf hash from components
121121
pub fn from_script(script: &Script, ver: LeafVersion) -> TapLeafHash {
122122
let mut eng = TapLeafHash::engine();
123-
ver.into_consensus()
123+
ver.to_consensus()
124124
.consensus_encode(&mut eng)
125125
.expect("engines don't error");
126126
script
@@ -703,7 +703,7 @@ impl ControlBlock {
703703

704704
/// Serialize to a writer. Returns the number of bytes written
705705
pub fn encode<Write: io::Write>(&self, mut writer: Write) -> io::Result<usize> {
706-
let first_byte: u8 = i32::from(self.output_key_parity) as u8 | self.leaf_version.into_consensus();
706+
let first_byte: u8 = i32::from(self.output_key_parity) as u8 | self.leaf_version.to_consensus();
707707
let mut bytes_written = 0;
708708
bytes_written += writer.write(&[first_byte])?;
709709
bytes_written += writer.write(&self.internal_key.serialize())?;
@@ -778,7 +778,7 @@ impl FutureLeafVersion {
778778

779779
/// Get consensus representation of the future leaf version.
780780
#[inline]
781-
pub fn into_consensus(self) -> u8 {
781+
pub fn to_consensus(self) -> u8 {
782782
self.0
783783
}
784784
}
@@ -838,10 +838,10 @@ impl LeafVersion {
838838
}
839839

840840
/// Get consensus representation of the [`LeafVersion`].
841-
pub fn into_consensus(self) -> u8 {
841+
pub fn to_consensus(self) -> u8 {
842842
match self {
843843
LeafVersion::TapScript => TAPROOT_LEAF_TAPSCRIPT,
844-
LeafVersion::Future(version) => version.into_consensus(),
844+
LeafVersion::Future(version) => version.to_consensus(),
845845
}
846846
}
847847
}
@@ -859,13 +859,13 @@ impl fmt::Display for LeafVersion {
859859

860860
impl fmt::LowerHex for LeafVersion {
861861
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
862-
fmt::LowerHex::fmt(&self.into_consensus(), f)
862+
fmt::LowerHex::fmt(&self.to_consensus(), f)
863863
}
864864
}
865865

866866
impl fmt::UpperHex for LeafVersion {
867867
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
868-
fmt::UpperHex::fmt(&self.into_consensus(), f)
868+
fmt::UpperHex::fmt(&self.to_consensus(), f)
869869
}
870870
}
871871

@@ -877,7 +877,7 @@ impl ::serde::Serialize for LeafVersion {
877877
where
878878
S: ::serde::Serializer,
879879
{
880-
serializer.serialize_u8(self.into_consensus())
880+
serializer.serialize_u8(self.to_consensus())
881881
}
882882
}
883883

@@ -1293,7 +1293,7 @@ mod test {
12931293
let addr = Address::p2tr(&secp, internal_key, merkle_root, Network::Bitcoin);
12941294
let spk = addr.script_pubkey();
12951295

1296-
assert_eq!(expected_output_key, output_key.into_inner());
1296+
assert_eq!(expected_output_key, output_key.to_inner());
12971297
assert_eq!(expected_tweak, tweak);
12981298
assert_eq!(expected_addr, addr);
12991299
assert_eq!(expected_spk, spk);

0 commit comments

Comments
 (0)