From ff13630b8cf937796c662e18b1f9f20ecb87812c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BChler?= Date: Sat, 7 Mar 2020 19:05:00 +0100 Subject: [PATCH] allow converting Box to Box for owned downcast --- lib/dnsbox-base/src/records/unknown.rs | 4 ++++ lib/dnsbox-base/src/ser/rrdata.rs | 2 ++ lib/dnsbox-derive/src/rrdata.rs | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/lib/dnsbox-base/src/records/unknown.rs b/lib/dnsbox-base/src/records/unknown.rs index 941cc0a..1515d9d 100644 --- a/lib/dnsbox-base/src/records/unknown.rs +++ b/lib/dnsbox-base/src/records/unknown.rs @@ -117,4 +117,8 @@ impl RRData for UnknownRecord { fn as_any(&self) -> &dyn ::std::any::Any { self as _ } + + fn as_box_any(self: Box) -> Box { + self as _ + } } diff --git a/lib/dnsbox-base/src/ser/rrdata.rs b/lib/dnsbox-base/src/ser/rrdata.rs index a45325e..d4b2505 100644 --- a/lib/dnsbox-base/src/ser/rrdata.rs +++ b/lib/dnsbox-base/src/ser/rrdata.rs @@ -108,6 +108,8 @@ pub trait RRData: RRDataPacket + RRDataText + fmt::Debug + 'static { fn as_any(&self) -> &dyn Any; + fn as_box_any(self: Box) -> Box; + // (type, rrdata) fn text(&self) -> Result<(String, String)> { let mut buf = String::new(); diff --git a/lib/dnsbox-derive/src/rrdata.rs b/lib/dnsbox-derive/src/rrdata.rs index 57e8e3e..5fda18a 100644 --- a/lib/dnsbox-derive/src/rrdata.rs +++ b/lib/dnsbox-derive/src/rrdata.rs @@ -66,6 +66,10 @@ pub fn rrdata_derive(s: synstructure::Structure) -> proc_macro2::TokenStream { fn as_any(&self) -> &::std::any::Any { self as _ } + + fn as_box_any(self: Box) -> Box { + self as _ + } }, );