From 9ff91eeffb1d5c93bf8c0fd5e1427b5e23a19768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BChler?= Date: Sun, 8 Sep 2019 15:34:28 +0200 Subject: [PATCH] use `dyn $trait` syntax --- dnsbox/src/bin/resolver/cache/mod.rs | 8 ++++---- dnsbox/src/bin/resolver/cache/root_hints.rs | 2 +- lib/dnsbox-base/src/packet/mod.rs | 2 +- lib/dnsbox-base/src/records/powerdns_tests.rs | 6 +++--- lib/dnsbox-base/src/records/registry.rs | 16 ++++++++-------- lib/dnsbox-base/src/records/unknown.rs | 4 ++-- lib/dnsbox-base/src/ser/rrdata.rs | 6 +++--- lib/dnsbox-base/src/ser/text/mod.rs | 8 ++++---- 8 files changed, 26 insertions(+), 26 deletions(-) diff --git a/dnsbox/src/bin/resolver/cache/mod.rs b/dnsbox/src/bin/resolver/cache/mod.rs index 7e2f9fe..1f5410e 100644 --- a/dnsbox/src/bin/resolver/cache/mod.rs +++ b/dnsbox/src/bin/resolver/cache/mod.rs @@ -20,13 +20,13 @@ pub enum Source { #[derive(Clone, Debug)] pub struct Entry { - rrset: Vec>, + rrset: Vec>, source: Source, ttl: u32, } impl Entry { - pub fn new(rrset: Vec>, source: Source) -> Self { + pub fn new(rrset: Vec>, source: Source) -> Self { unimplemented!() } @@ -95,7 +95,7 @@ impl InnerEntry { type NameEntry = HashMap; -pub type LookupFunction = Box Box>>; +pub type LookupFunction = Box Box>>; pub struct Cache { names: Rc>>, @@ -139,7 +139,7 @@ impl Cache { /// # Panics /// /// Panics when the `rrset` entries don't match `rrtype`. - pub fn insert_hint(&self, name: DnsName, rrtype: Type, rrset: Vec>) { + pub fn insert_hint(&self, name: DnsName, rrtype: Type, rrset: Vec>) { for e in &rrset { assert_eq!(rrtype, e.rr_type()); } diff --git a/dnsbox/src/bin/resolver/cache/root_hints.rs b/dnsbox/src/bin/resolver/cache/root_hints.rs index 8e2c603..ef6792d 100644 --- a/dnsbox/src/bin/resolver/cache/root_hints.rs +++ b/dnsbox/src/bin/resolver/cache/root_hints.rs @@ -21,7 +21,7 @@ static DATA: [(&str, &str, &str); 13] = [ ]; pub fn load_hints(cache: &super::Cache) { - let mut root_ns_set: Vec> = Vec::new(); + let mut root_ns_set: Vec> = Vec::new(); for &(name, ipv4, ipv6) in &DATA { let name = name.parse::().expect("invalid root hint name"); diff --git a/lib/dnsbox-base/src/packet/mod.rs b/lib/dnsbox-base/src/packet/mod.rs index b0fbb15..bbe50ad 100644 --- a/lib/dnsbox-base/src/packet/mod.rs +++ b/lib/dnsbox-base/src/packet/mod.rs @@ -104,7 +104,7 @@ pub struct Resource { pub name: DnsCompressedName, pub class: Class, pub ttl: u32, - pub data: Box, + pub data: Box, } impl DnsPacketData for Resource { diff --git a/lib/dnsbox-base/src/records/powerdns_tests.rs b/lib/dnsbox-base/src/records/powerdns_tests.rs index 1955aa5..cb355bb 100644 --- a/lib/dnsbox-base/src/records/powerdns_tests.rs +++ b/lib/dnsbox-base/src/records/powerdns_tests.rs @@ -55,7 +55,7 @@ fn get_first_answer_rdata(packet: Bytes) -> Result { Ok(data.get_ref().slice(pos, pos + rdlength)) } -fn serialized_answer(rrdata: Box) -> Result { +fn serialized_answer(rrdata: Box) -> Result { let mut p = DnsPacket{ question: vec![ Question { @@ -93,7 +93,7 @@ fn check(q: Type, text_input: &'static str, canonic: Option<&'static str>, raw: context.set_record_type(q); context.set_last_ttl(3600); - let d_zone: Box = text::parse_with(text_input, |data| { + let d_zone: Box = text::parse_with(text_input, |data| { registry::parse_rr_data(&context, data) }).unwrap(); @@ -111,7 +111,7 @@ fn check(q: Type, text_input: &'static str, canonic: Option<&'static str>, raw: // pdns tests deserialize `zone_as_wire` (from below) here, but we // make sure it's the same anyway let d_wire_packet = deserialize_with(fake_packet(q, raw), DnsPacket::deserialize).unwrap(); - let d_wire: &Box = &d_wire_packet.answer[0].data; + let d_wire: &Box = &d_wire_packet.answer[0].data; let d_wire_text = d_wire.text().unwrap(); diff --git a/lib/dnsbox-base/src/records/registry.rs b/lib/dnsbox-base/src/records/registry.rs index 8898ed5..cbc7d09 100644 --- a/lib/dnsbox-base/src/records/registry.rs +++ b/lib/dnsbox-base/src/records/registry.rs @@ -42,7 +42,7 @@ pub fn known_name_to_type(name: &str) -> Option { Some(t) } -pub fn deserialize_rr_data(ttl: u32, rr_class: Class, rr_type: Type, data: &mut Cursor) -> Result> { +pub fn deserialize_rr_data(ttl: u32, rr_class: Class, rr_type: Type, data: &mut Cursor) -> Result> { let registry = registry(); match registry.type_parser.get(&rr_type) { Some(p) => p.deserialize_rr_data(ttl, rr_class, rr_type, data), @@ -50,7 +50,7 @@ pub fn deserialize_rr_data(ttl: u32, rr_class: Class, rr_type: Type, data: &mut } } -pub fn parse_rr_data(context: &DnsTextContext, data: &mut &str) -> Result> { +pub fn parse_rr_data(context: &DnsTextContext, data: &mut &str) -> Result> { let registry = registry(); let t = match context.record_type() { Some(t) => t, @@ -80,17 +80,17 @@ trait RRDataTypeParse: 'static { TypeId::of::() } - fn deserialize_rr_data(&self, ttl: u32, rr_class: Class, rr_type: Type, data: &mut Cursor) -> Result>; + fn deserialize_rr_data(&self, ttl: u32, rr_class: Class, rr_type: Type, data: &mut Cursor) -> Result>; - fn parse_rr_data(&self, context: &DnsTextContext, data: &mut &str) -> Result>; + fn parse_rr_data(&self, context: &DnsTextContext, data: &mut &str) -> Result>; } impl RRDataTypeParse for TagRRDataType { - fn deserialize_rr_data(&self, ttl: u32, rr_class: Class, rr_type: Type, data: &mut Cursor) -> Result> { + fn deserialize_rr_data(&self, ttl: u32, rr_class: Class, rr_type: Type, data: &mut Cursor) -> Result> { T::deserialize_rr_data(ttl, rr_class, rr_type, data).map(|d| Box::new(d) as _) } - fn parse_rr_data(&self, context: &DnsTextContext, data: &mut &str) -> Result> { + fn parse_rr_data(&self, context: &DnsTextContext, data: &mut &str) -> Result> { T::dns_parse_rr_data(context, data).map(|d| Box::new(d) as _) } } @@ -99,7 +99,7 @@ struct Registry { // store (ascii) upper-case names. names_to_type: HashMap, Type>, type_names: HashMap, - type_parser: HashMap>, + type_parser: HashMap>, // make sure registrations are in order prev_type: Option, } @@ -232,7 +232,7 @@ impl Registry { fn check_registration(&self) { assert_eq!(self.names_to_type.get(T::NAME.as_bytes()), Some(&T::TYPE)); - let p: &RRDataTypeParse = &**self.type_parser.get(&T::TYPE).expect("no parser registered"); + let p: &dyn RRDataTypeParse = &**self.type_parser.get(&T::TYPE).expect("no parser registered"); let tid = TypeId::of::>(); assert_eq!(p.type_id(), tid); } diff --git a/lib/dnsbox-base/src/records/unknown.rs b/lib/dnsbox-base/src/records/unknown.rs index 40810c1..1dc83ec 100644 --- a/lib/dnsbox-base/src/records/unknown.rs +++ b/lib/dnsbox-base/src/records/unknown.rs @@ -90,11 +90,11 @@ impl RRDataText for UnknownRecord { } impl RRData for UnknownRecord { - fn clone_box(&self) -> Box { + fn clone_box(&self) -> Box { Box::new(self.clone()) as _ } - fn as_any(&self) -> &::std::any::Any { + fn as_any(&self) -> &dyn ::std::any::Any { self as _ } } diff --git a/lib/dnsbox-base/src/ser/rrdata.rs b/lib/dnsbox-base/src/ser/rrdata.rs index 68c96c8..3b16e39 100644 --- a/lib/dnsbox-base/src/ser/rrdata.rs +++ b/lib/dnsbox-base/src/ser/rrdata.rs @@ -76,9 +76,9 @@ impl RRDataText for T { } pub trait RRData: RRDataPacket + RRDataText + fmt::Debug + 'static { - fn clone_box(&self) -> Box; + fn clone_box(&self) -> Box; - fn as_any(&self) -> &Any; + fn as_any(&self) -> &dyn Any; // (type, rrdata) fn text(&self) -> Result<(String, String)> { @@ -99,7 +99,7 @@ pub trait RRData: RRDataPacket + RRDataText + fmt::Debug + 'static { } } -impl Clone for Box { +impl Clone for Box { fn clone(&self) -> Self { self.clone_box() } diff --git a/lib/dnsbox-base/src/ser/text/mod.rs b/lib/dnsbox-base/src/ser/text/mod.rs index c287c7e..9fec5c8 100644 --- a/lib/dnsbox-base/src/ser/text/mod.rs +++ b/lib/dnsbox-base/src/ser/text/mod.rs @@ -57,12 +57,12 @@ pub fn escape(data: &[u8]) -> String { /// Each call to write!() makes sure a space is emitted to separate it /// from previous fields. pub struct DnsTextFormatter<'a> { - w: &'a mut fmt::Write, + w: &'a mut dyn fmt::Write, need_space: bool, } impl<'a> DnsTextFormatter<'a> { - pub fn new(w: &'a mut fmt::Write) -> Self { + pub fn new(w: &'a mut dyn fmt::Write) -> Self { DnsTextFormatter { w: w, need_space: false, @@ -85,7 +85,7 @@ impl<'a> DnsTextFormatter<'a> { /// direct access to underlying output; you'll need to call /// `next_field` and `end_field` manually. - pub fn inner(&mut self) -> &mut fmt::Write { + pub fn inner(&mut self) -> &mut dyn fmt::Write { self.w } @@ -107,7 +107,7 @@ pub struct DnsTextFormatField<'a: 'b, 'b> { } impl<'a, 'b> ::std::ops::Deref for DnsTextFormatField<'a, 'b> { - type Target = fmt::Write + 'a; + type Target = dyn fmt::Write + 'a; fn deref(&self) -> &Self::Target { self.inner.w