Add the dyn keyword where appropriate

This commit is contained in:
Elichai Turkel 2020-09-14 17:55:42 +03:00
parent efe1a55819
commit 023fae1f65
No known key found for this signature in database
GPG Key ID: 9383CDE9E8E66A7F
11 changed files with 30 additions and 29 deletions

View File

@ -422,7 +422,7 @@ impl Script {
} }
/// Write the assembly decoding of the script to the formatter. /// Write the assembly decoding of the script to the formatter.
pub fn fmt_asm(&self, f: &mut fmt::Write) -> fmt::Result { pub fn fmt_asm(&self, f: &mut dyn fmt::Write) -> fmt::Result {
let mut index = 0; let mut index = 0;
while index < self.0.len() { while index < self.0.len() {
let opcode = opcodes::All::from(self.0[index]); let opcode = opcodes::All::from(self.0[index]);

View File

@ -24,7 +24,7 @@
//! //!
use std::default::Default; use std::default::Default;
use std::{fmt, io}; use std::{error, fmt, io};
use hashes::{self, Hash, sha256d}; use hashes::{self, Hash, sha256d};
use hashes::hex::FromHex; use hashes::hex::FromHex;
@ -129,12 +129,12 @@ impl fmt::Display for ParseOutPointError {
} }
#[allow(deprecated)] #[allow(deprecated)]
impl ::std::error::Error for ParseOutPointError { impl error::Error for ParseOutPointError {
fn description(&self) -> &str { fn description(&self) -> &str {
"description() is deprecated; use Display" "description() is deprecated; use Display"
} }
fn cause(&self) -> Option<&::std::error::Error> { fn cause(&self) -> Option<&dyn error::Error> {
match *self { match *self {
ParseOutPointError::Txid(ref e) => Some(e), ParseOutPointError::Txid(ref e) => Some(e),
ParseOutPointError::Vout(ref e) => Some(e), ParseOutPointError::Vout(ref e) => Some(e),

View File

@ -111,7 +111,7 @@ impl fmt::Display for Error {
#[allow(deprecated)] #[allow(deprecated)]
impl error::Error for Error { impl error::Error for Error {
fn cause(&self) -> Option<&error::Error> { fn cause(&self) -> Option<&dyn error::Error> {
match *self { match *self {
Error::Io(ref e) => Some(e), Error::Io(ref e) => Some(e),
Error::Psbt(ref e) => Some(e), Error::Psbt(ref e) => Some(e),

View File

@ -66,7 +66,7 @@ impl error::Error for Error {
"description() is deprecated; use Display" "description() is deprecated; use Display"
} }
fn cause(&self) -> Option<&error::Error> { fn cause(&self) -> Option<&dyn error::Error> {
match *self { match *self {
Error::Io(ref e) => Some(e), Error::Io(ref e) => Some(e),
Error::SocketMutexPoisoned | Error::SocketNotConnectedToPeer => None, Error::SocketMutexPoisoned | Error::SocketNotConnectedToPeer => None,

View File

@ -38,6 +38,7 @@
use std::fmt::{self, Display, Formatter}; use std::fmt::{self, Display, Formatter};
use std::str::FromStr; use std::str::FromStr;
use std::error;
use bech32; use bech32;
use hashes::Hash; use hashes::Hash;
@ -87,8 +88,8 @@ impl fmt::Display for Error {
} }
#[allow(deprecated)] #[allow(deprecated)]
impl ::std::error::Error for Error { impl error::Error for Error {
fn cause(&self) -> Option<&::std::error::Error> { fn cause(&self) -> Option<&dyn error::Error> {
match *self { match *self {
Error::Base58(ref e) => Some(e), Error::Base58(ref e) => Some(e),
Error::Bech32(ref e) => Some(e), Error::Bech32(ref e) => Some(e),

View File

@ -215,7 +215,7 @@ fn parse_signed_to_satoshi(
fn fmt_satoshi_in( fn fmt_satoshi_in(
satoshi: u64, satoshi: u64,
negative: bool, negative: bool,
f: &mut fmt::Write, f: &mut dyn fmt::Write,
denom: Denomination, denom: Denomination,
) -> fmt::Result { ) -> fmt::Result {
if negative { if negative {
@ -365,7 +365,7 @@ impl Amount {
/// Format the value of this [Amount] in the given denomination. /// Format the value of this [Amount] in the given denomination.
/// ///
/// Does not include the denomination. /// Does not include the denomination.
pub fn fmt_value_in(self, f: &mut fmt::Write, denom: Denomination) -> fmt::Result { pub fn fmt_value_in(self, f: &mut dyn fmt::Write, denom: Denomination) -> fmt::Result {
fmt_satoshi_in(self.as_sat(), false, f, denom) fmt_satoshi_in(self.as_sat(), false, f, denom)
} }
@ -643,7 +643,7 @@ impl SignedAmount {
/// Format the value of this [SignedAmount] in the given denomination. /// Format the value of this [SignedAmount] in the given denomination.
/// ///
/// Does not include the denomination. /// Does not include the denomination.
pub fn fmt_value_in(self, f: &mut fmt::Write, denom: Denomination) -> fmt::Result { pub fn fmt_value_in(self, f: &mut dyn fmt::Write, denom: Denomination) -> fmt::Result {
let sats = self.as_sat().checked_abs().map(|a: i64| a as u64).unwrap_or_else(|| { let sats = self.as_sat().checked_abs().map(|a: i64| a as u64).unwrap_or_else(|| {
// We could also hard code this into `9223372036854775808` // We could also hard code this into `9223372036854775808`
u64::max_value() - self.as_sat() as u64 +1 u64::max_value() - self.as_sat() as u64 +1

View File

@ -133,13 +133,13 @@ impl BlockFilter {
} }
/// match any query pattern /// match any query pattern
pub fn match_any(&self, block_hash: &BlockHash, query: &mut Iterator<Item=&[u8]>) -> Result<bool, Error> { pub fn match_any(&self, block_hash: &BlockHash, query: &mut dyn Iterator<Item=&[u8]>) -> Result<bool, Error> {
let filter_reader = BlockFilterReader::new(block_hash); let filter_reader = BlockFilterReader::new(block_hash);
filter_reader.match_any(&mut Cursor::new(self.content.as_slice()), query) filter_reader.match_any(&mut Cursor::new(self.content.as_slice()), query)
} }
/// match all query pattern /// match all query pattern
pub fn match_all(&self, block_hash: &BlockHash, query: &mut Iterator<Item=&[u8]>) -> Result<bool, Error> { pub fn match_all(&self, block_hash: &BlockHash, query: &mut dyn Iterator<Item=&[u8]>) -> Result<bool, Error> {
let filter_reader = BlockFilterReader::new(block_hash); let filter_reader = BlockFilterReader::new(block_hash);
filter_reader.match_all(&mut Cursor::new(self.content.as_slice()), query) filter_reader.match_all(&mut Cursor::new(self.content.as_slice()), query)
} }
@ -153,7 +153,7 @@ pub struct BlockFilterWriter<'a> {
impl<'a> BlockFilterWriter<'a> { impl<'a> BlockFilterWriter<'a> {
/// Create a block filter writer /// Create a block filter writer
pub fn new(writer: &'a mut io::Write, block: &'a Block) -> BlockFilterWriter<'a> { pub fn new(writer: &'a mut dyn io::Write, block: &'a Block) -> BlockFilterWriter<'a> {
let block_hash_as_int = block.block_hash().into_inner(); let block_hash_as_int = block.block_hash().into_inner();
let k0 = endian::slice_to_u64_le(&block_hash_as_int[0..8]); let k0 = endian::slice_to_u64_le(&block_hash_as_int[0..8]);
let k1 = endian::slice_to_u64_le(&block_hash_as_int[8..16]); let k1 = endian::slice_to_u64_le(&block_hash_as_int[8..16]);
@ -214,12 +214,12 @@ impl BlockFilterReader {
} }
/// match any query pattern /// match any query pattern
pub fn match_any(&self, reader: &mut io::Read, query: &mut Iterator<Item=&[u8]>) -> Result<bool, Error> { pub fn match_any(&self, reader: &mut dyn io::Read, query: &mut dyn Iterator<Item=&[u8]>) -> Result<bool, Error> {
self.reader.match_any(reader, query) self.reader.match_any(reader, query)
} }
/// match all query pattern /// match all query pattern
pub fn match_all(&self, reader: &mut io::Read, query: &mut Iterator<Item=&[u8]>) -> Result<bool, Error> { pub fn match_all(&self, reader: &mut dyn io::Read, query: &mut dyn Iterator<Item=&[u8]>) -> Result<bool, Error> {
self.reader.match_all(reader, query) self.reader.match_all(reader, query)
} }
} }
@ -238,7 +238,7 @@ impl GCSFilterReader {
} }
/// match any query pattern /// match any query pattern
pub fn match_any(&self, reader: &mut io::Read, query: &mut Iterator<Item=&[u8]>) -> Result<bool, Error> { pub fn match_any(&self, reader: &mut dyn io::Read, query: &mut dyn Iterator<Item=&[u8]>) -> Result<bool, Error> {
let mut decoder = reader; let mut decoder = reader;
let n_elements: VarInt = Decodable::consensus_decode(&mut decoder).unwrap_or(VarInt(0)); let n_elements: VarInt = Decodable::consensus_decode(&mut decoder).unwrap_or(VarInt(0));
let reader = &mut decoder; let reader = &mut decoder;
@ -278,7 +278,7 @@ impl GCSFilterReader {
} }
/// match all query pattern /// match all query pattern
pub fn match_all(&self, reader: &mut io::Read, query: &mut Iterator<Item=&[u8]>) -> Result<bool, Error> { pub fn match_all(&self, reader: &mut dyn io::Read, query: &mut dyn Iterator<Item=&[u8]>) -> Result<bool, Error> {
let mut decoder = reader; let mut decoder = reader;
let n_elements: VarInt = Decodable::consensus_decode(&mut decoder).unwrap_or(VarInt(0)); let n_elements: VarInt = Decodable::consensus_decode(&mut decoder).unwrap_or(VarInt(0));
let reader = &mut decoder; let reader = &mut decoder;
@ -340,14 +340,14 @@ fn map_to_range(hash: u64, nm: u64) -> u64 {
/// Colomb-Rice encoded filter writer /// Colomb-Rice encoded filter writer
pub struct GCSFilterWriter<'a> { pub struct GCSFilterWriter<'a> {
filter: GCSFilter, filter: GCSFilter,
writer: &'a mut io::Write, writer: &'a mut dyn io::Write,
elements: HashSet<Vec<u8>>, elements: HashSet<Vec<u8>>,
m: u64 m: u64
} }
impl<'a> GCSFilterWriter<'a> { impl<'a> GCSFilterWriter<'a> {
/// Create a new GCS writer wrapping a generic writer, with specific seed to siphash /// Create a new GCS writer wrapping a generic writer, with specific seed to siphash
pub fn new(writer: &'a mut io::Write, k0: u64, k1: u64, m: u64, p: u8) -> GCSFilterWriter<'a> { pub fn new(writer: &'a mut dyn io::Write, k0: u64, k1: u64, m: u64, p: u8) -> GCSFilterWriter<'a> {
GCSFilterWriter { GCSFilterWriter {
filter: GCSFilter::new(k0, k1, p), filter: GCSFilter::new(k0, k1, p),
writer, writer,
@ -436,12 +436,12 @@ impl GCSFilter {
pub struct BitStreamReader<'a> { pub struct BitStreamReader<'a> {
buffer: [u8; 1], buffer: [u8; 1],
offset: u8, offset: u8,
reader: &'a mut io::Read, reader: &'a mut dyn io::Read,
} }
impl<'a> BitStreamReader<'a> { impl<'a> BitStreamReader<'a> {
/// Create a new BitStreamReader that reads bitwise from a given reader /// Create a new BitStreamReader that reads bitwise from a given reader
pub fn new(reader: &'a mut io::Read) -> BitStreamReader { pub fn new(reader: &'a mut dyn io::Read) -> BitStreamReader {
BitStreamReader { BitStreamReader {
buffer: [0u8], buffer: [0u8],
reader: reader, reader: reader,
@ -474,12 +474,12 @@ impl<'a> BitStreamReader<'a> {
pub struct BitStreamWriter<'a> { pub struct BitStreamWriter<'a> {
buffer: [u8; 1], buffer: [u8; 1],
offset: u8, offset: u8,
writer: &'a mut io::Write, writer: &'a mut dyn io::Write,
} }
impl<'a> BitStreamWriter<'a> { impl<'a> BitStreamWriter<'a> {
/// Create a new BitStreamWriter that writes bitwise to a given writer /// Create a new BitStreamWriter that writes bitwise to a given writer
pub fn new(writer: &'a mut io::Write) -> BitStreamWriter { pub fn new(writer: &'a mut dyn io::Write) -> BitStreamWriter {
BitStreamWriter { BitStreamWriter {
buffer: [0u8], buffer: [0u8],
writer: writer, writer: writer,

View File

@ -404,7 +404,7 @@ impl fmt::Display for Error {
} }
impl error::Error for Error { impl error::Error for Error {
fn cause(&self) -> Option<&error::Error> { fn cause(&self) -> Option<&dyn error::Error> {
if let Error::Ecdsa(ref e) = *self { if let Error::Ecdsa(ref e) = *self {
Some(e) Some(e)
} else { } else {

View File

@ -73,7 +73,7 @@ impl fmt::Display for Error {
#[allow(deprecated)] #[allow(deprecated)]
impl error::Error for Error { impl error::Error for Error {
fn cause(&self) -> Option<&error::Error> { fn cause(&self) -> Option<&dyn error::Error> {
match *self { match *self {
Error::Secp(ref e) => Some(e), Error::Secp(ref e) => Some(e),
Error::Script(ref e) => Some(e), Error::Script(ref e) => Some(e),

View File

@ -46,7 +46,7 @@ impl fmt::Display for Error {
} }
impl error::Error for Error { impl error::Error for Error {
fn cause(&self) -> Option<&error::Error> { fn cause(&self) -> Option<&dyn error::Error> {
match *self { match *self {
Error::Base58(ref e) => Some(e), Error::Base58(ref e) => Some(e),
Error::Secp256k1(ref e) => Some(e), Error::Secp256k1(ref e) => Some(e),
@ -193,7 +193,7 @@ impl PrivateKey {
} }
/// Format the private key to WIF format. /// Format the private key to WIF format.
pub fn fmt_wif(&self, fmt: &mut fmt::Write) -> fmt::Result { pub fn fmt_wif(&self, fmt: &mut dyn fmt::Write) -> fmt::Result {
let mut ret = [0; 34]; let mut ret = [0; 34];
ret[0] = match self.network { ret[0] = match self.network {
Network::Bitcoin => 128, Network::Bitcoin => 128,

View File

@ -85,7 +85,7 @@ impl fmt::Display for Error {
#[allow(deprecated)] #[allow(deprecated)]
impl error::Error for Error { impl error::Error for Error {
fn cause(&self) -> Option<&error::Error> { fn cause(&self) -> Option<&dyn error::Error> {
match *self { match *self {
Error::Encode(ref e) => Some(e), Error::Encode(ref e) => Some(e),
Error::Network(ref e) => Some(e), Error::Network(ref e) => Some(e),