diff --git a/Cargo.lock b/Cargo.lock index 699bbdf36..a8f6bc6bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -647,9 +647,9 @@ dependencies = [ [[package]] name = "octseq" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df8a0b46f254482682d1e09d35af3e3e9cfec83e2617ebbfd9434c3d3bc8864e" +checksum = "182eab3e1cd9cdc0ecf1ce3342d9844f3dc7d098f0694569bfdf327b612d69fd" dependencies = [ "bytes", "heapless", diff --git a/Cargo.toml b/Cargo.toml index 9fbd55d23..99dc9803a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,7 +40,7 @@ jiff = { version = "0.2.1", default-features = false } arbitrary = { version = "1.4.1", optional = true, features = ["derive"] } bumpalo = { version = "3.12", optional = true } constant_time_eq = { version = "0.4.2", optional = true } -octseq = { version = "0.6.0", default-features = false } +octseq = { version = "0.6.1", default-features = false } rand = { version = "0.10.1", optional = true } arc-swap = { version = "1.7.0", optional = true } bytes = { version = "1.2", optional = true, default-features = false } @@ -57,7 +57,7 @@ proc-macro2 = { version = "1.0.69", optional = true } # Force proc-macro2 to ring = { version = "0.17.2", optional = true } rustversion = { version = "1", optional = true } secrecy = { version = "0.10", optional = true } -serde = { version = "1.0.130", optional = true, features = ["derive"] } +serde = { version = "1.0.130", optional = true, default-features = false, features = ["derive"] } siphasher = { version = "1", optional = true } smallvec = { version = "1.3", optional = true } tokio = { version = "1.33", optional = true, features = ["io-util", "macros", "net", "time", "sync", "rt-multi-thread" ] } @@ -70,15 +70,15 @@ tracing-subscriber = { version = "0.3.18", optional = true, features = ["env-fil default = ["std", "rand"] # Support for libraries -alloc = ["jiff/alloc"] +alloc = ["jiff/alloc", "octseq/alloc", "serde?/alloc"] bumpalo = ["dep:bumpalo", "std"] bytes = ["dep:bytes", "octseq/bytes"] chrono = ["dep:chrono"] heapless = ["dep:heapless", "octseq/heapless"] rand = ["dep:rand"] -serde = ["std", "dep:serde", "octseq/serde"] +serde = ["dep:serde", "octseq/serde"] smallvec = ["dep:smallvec", "octseq/smallvec"] -std = ["alloc", "dep:hashbrown", "bumpalo?/std", "bytes?/std", "octseq/std", "jiff/std"] +std = ["alloc", "dep:hashbrown", "bumpalo?/std", "bytes?/std", "octseq/std", "jiff/std", "serde?/std"] tracing = ["dep:log", "dep:tracing"] # Cryptographic backends diff --git a/src/base/charstr.rs b/src/base/charstr.rs index dfeb41b2d..e0fb2f363 100644 --- a/src/base/charstr.rs +++ b/src/base/charstr.rs @@ -26,6 +26,8 @@ use super::cmp::CanonicalOrd; use super::scan::{BadSymbol, Scanner, Symbol, SymbolCharsError}; use super::wire::{Compose, ParseError}; +#[cfg(feature = "alloc")] +use alloc::vec::Vec; #[cfg(feature = "bytes")] use bytes::BytesMut; use core::{cmp, fmt, hash, mem, str}; @@ -36,8 +38,6 @@ use octseq::{ EmptyBuilder, FromBuilder, IntoBuilder, Octets, OctetsBuilder, OctetsFrom, Parser, ShortBuf, Truncate, }; -#[cfg(feature = "std")] -use std::vec::Vec; //------------ CharStr ------------------------------------------------------- @@ -661,10 +661,10 @@ where }) } - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn visit_byte_buf( self, - value: std::vec::Vec, + value: alloc::vec::Vec, ) -> Result { self.0.visit_byte_buf(value).and_then(|octets| { CharStr::from_octets(octets).map_err(E::custom) @@ -757,7 +757,7 @@ impl> CharStrBuilder { } } -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] impl CharStrBuilder> { /// Creates a new empty characater string builder atop an octets vec. #[must_use] @@ -1211,7 +1211,7 @@ impl core::error::Error for PresentationError {} //============ Testing ======================================================= #[cfg(test)] -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod test { use super::*; use octseq::builder::infallible; @@ -1242,7 +1242,7 @@ mod test { #[test] fn from_str() { - use std::str::{from_utf8, FromStr}; + use core::str::{from_utf8, FromStr}; type Cs = CharStr>; @@ -1319,7 +1319,7 @@ mod test { #[test] fn ord() { - use std::cmp::Ordering::*; + use core::cmp::Ordering::*; is_ord(b"abc", b"ABC", Equal); is_ord(b"abc", b"a", Greater); diff --git a/src/base/header.rs b/src/base/header.rs index f903e2b1a..4674afcfb 100644 --- a/src/base/header.rs +++ b/src/base/header.rs @@ -125,13 +125,13 @@ impl Header { /// incoming responses to their queries. /// /// When choosing an ID for an outgoing message, make sure it is random - /// to avoid spoofing by guessing the message ID. If `std` support + /// to avoid spoofing by guessing the message ID. If `rand` support /// is enabled, the method #[cfg_attr( - feature = "std", + feature = "rand", doc = "[`set_random_id`][Self::set_random_id]" )] - #[cfg_attr(not(feature = "std"), doc = "`set_random_id`")] + #[cfg_attr(not(feature = "rand"), doc = "`set_random_id`")] /// can be used for this purpose. #[must_use] pub fn id(self) -> u16 { @@ -961,9 +961,9 @@ mod test { use super::*; #[test] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn for_slice() { - use std::vec::Vec; + use alloc::vec::Vec; let header = b"\x01\x02\x00\x00\x12\x34\x56\x78\x9a\xbc\xde\xf0"; let mut vec = Vec::from(&header[..]); @@ -1119,7 +1119,7 @@ mod test { assert!(c.inc_arcount().is_err()); } - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] #[test] fn flags_display() { let f = Flags::new(); @@ -1140,7 +1140,7 @@ mod test { assert_eq!(format!("{}", f), "RD CD"); } - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] #[test] fn flags_from_str() { let f1 = Flags::from_str("").unwrap(); diff --git a/src/base/iana/class.rs b/src/base/iana/class.rs index ae859d7e2..f44c3001e 100644 --- a/src/base/iana/class.rs +++ b/src/base/iana/class.rs @@ -76,7 +76,7 @@ mod test { assert_tokens(&Class(5).compact(), &[Token::U16(5)]); } - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] #[test] fn debug() { use super::Class; diff --git a/src/base/message.rs b/src/base/message.rs index 3ee81e57a..247ce057d 100644 --- a/src/base/message.rs +++ b/src/base/message.rs @@ -1352,17 +1352,17 @@ impl core::error::Error for CopyRecordsError {} #[cfg(test)] mod test { use super::*; - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] use crate::base::message_builder::MessageBuilder; - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] use crate::base::name::Name; - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] use crate::rdata::{AllRecordData, Ns}; - #[cfg(feature = "std")] - use std::vec::Vec; + #[cfg(feature = "alloc")] + use alloc::vec::Vec; // Helper for test cases - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn get_test_message() -> Message> { let msg = MessageBuilder::new_vec(); let mut msg = msg.answer(); @@ -1389,7 +1389,7 @@ mod test { } #[test] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn canonical_name() { use crate::rdata::A; @@ -1447,7 +1447,7 @@ mod test { } #[test] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn message_iterator() { let msg = get_test_message(); let mut iter = msg.iter(); @@ -1462,7 +1462,7 @@ mod test { } #[test] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn copy_records() { let msg = get_test_message(); let target = MessageBuilder::new_vec().question(); diff --git a/src/base/message_builder.rs b/src/base/message_builder.rs index 9f7506016..7b28766de 100644 --- a/src/base/message_builder.rs +++ b/src/base/message_builder.rs @@ -65,8 +65,8 @@ //! The following example builds a message with both name compression and //! the stream length and simply puts two A records into it. //! -#![cfg_attr(feature = "std", doc = "```")] -#![cfg_attr(not(feature = "std"), doc = "```ignore")] +#![cfg_attr(feature = "alloc", doc = "```")] +#![cfg_attr(not(feature = "alloc"), doc = "```ignore")] //! use std::str::FromStr; //! use domain::base::{ //! Name, MessageBuilder, Rtype, StaticCompressor, StreamTarget @@ -137,6 +137,8 @@ use super::opt::{ComposeOptData, OptHeader, OptRecord}; use super::question::ComposeQuestion; use super::record::ComposeRecord; use super::wire::{Compose, Composer}; +#[cfg(feature = "alloc")] +use alloc::vec::Vec; #[cfg(feature = "bytes")] use bytes::BytesMut; use core::ops::{Deref, DerefMut}; @@ -145,7 +147,7 @@ use core::{fmt, mem}; use hashbrown::HashTable; #[cfg(feature = "std")] use octseq::array::Array; -#[cfg(any(feature = "std", feature = "bytes"))] +#[cfg(any(feature = "alloc", feature = "bytes"))] use octseq::builder::infallible; use octseq::builder::{FreezeBuilder, OctetsBuilder, ShortBuf, Truncate}; use octseq::octets::Octets; @@ -153,8 +155,6 @@ use octseq::octets::Octets; use std::collections::{hash_map::RandomState, HashMap}; #[cfg(feature = "std")] use std::hash::BuildHasher; -#[cfg(feature = "std")] -use std::vec::Vec; //------------ MessageBuilder ------------------------------------------------ @@ -201,7 +201,7 @@ impl MessageBuilder { } } -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] impl MessageBuilder> { /// Creates a new message builder atop a `Vec`. #[must_use] @@ -210,7 +210,7 @@ impl MessageBuilder> { } } -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] impl MessageBuilder>> { /// Creates a new builder for a streamable message atop a `Vec`. #[must_use] @@ -599,8 +599,8 @@ impl QuestionBuilder { /// /// In other words, the options are: /// - #[cfg_attr(feature = "std", doc = "```")] - #[cfg_attr(not(feature = "std"), doc = "```ignore")] + #[cfg_attr(feature = "alloc", doc = "```")] + #[cfg_attr(not(feature = "alloc"), doc = "```ignore")] /// use domain::base::{Name, MessageBuilder, Question, Rtype}; /// use domain::base::iana::Class; /// @@ -851,8 +851,8 @@ impl AnswerBuilder { /// /// In other words, you can do the following things: /// - #[cfg_attr(feature = "std", doc = "```")] - #[cfg_attr(not(feature = "std"), doc = "```ignore")] + #[cfg_attr(feature = "alloc", doc = "```")] + #[cfg_attr(not(feature = "alloc"), doc = "```ignore")] /// use domain::base::{Name, MessageBuilder, Record, Rtype, Ttl}; /// use domain::base::iana::Class; /// use domain::rdata::A; @@ -1116,8 +1116,8 @@ impl AuthorityBuilder { /// /// In other words, you can do the following things: /// - #[cfg_attr(feature = "std", doc = "```")] - #[cfg_attr(not(feature = "std"), doc = "```ignore")] + #[cfg_attr(feature = "alloc", doc = "```")] + #[cfg_attr(not(feature = "alloc"), doc = "```ignore")] /// use domain::base::{Name, MessageBuilder, Record, Rtype, Ttl}; /// use domain::base::iana::Class; /// use domain::rdata::A; @@ -1374,8 +1374,8 @@ impl AdditionalBuilder { /// /// In other words, you can do the following things: /// - #[cfg_attr(feature = "std", doc = "```")] - #[cfg_attr(not(feature = "std"), doc = "```ignore")] + #[cfg_attr(feature = "alloc", doc = "```")] + #[cfg_attr(not(feature = "alloc"), doc = "```ignore")] /// use domain::base::{Name, MessageBuilder, Record, Rtype, Ttl}; /// use domain::base::iana::Class; /// use domain::rdata::A; @@ -1849,7 +1849,7 @@ impl StreamTarget { } } -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] impl StreamTarget> { /// Creates a stream target atop an empty `Vec`. #[must_use] diff --git a/src/base/name/absolute.rs b/src/base/name/absolute.rs index 7ffe6fae6..8f03308de 100644 --- a/src/base/name/absolute.rs +++ b/src/base/name/absolute.rs @@ -10,6 +10,8 @@ use super::builder::{FromStrError, NameBuilder, PushError}; use super::label::{Label, LabelTypeError, SplitLabelError}; use super::relative::{NameIter, RelativeName}; use super::traits::{FlattenInto, ToLabelIter, ToName}; +#[cfg(feature = "alloc")] +use alloc::vec::Vec; #[cfg(feature = "bytes")] use bytes::Bytes; use core::ops::{Bound, RangeBounds}; @@ -22,8 +24,6 @@ use octseq::octets::{Octets, OctetsFrom}; use octseq::parse::Parser; #[cfg(feature = "serde")] use octseq::serde::{DeserializeOctets, SerializeOctets}; -#[cfg(feature = "std")] -use std::vec::Vec; //------------ Name ---------------------------------------------------------- @@ -284,7 +284,7 @@ impl Name<&'static [u8]> { } } -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] impl Name> { /// Creates a domain name for the root label only atop a `Vec`. #[must_use] @@ -1048,10 +1048,10 @@ where }) } - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn visit_byte_buf( self, - value: std::vec::Vec, + value: alloc::vec::Vec, ) -> Result { self.0.visit_byte_buf(value).and_then(|octets| { Name::from_octets(octets).map_err(E::custom) @@ -1244,7 +1244,7 @@ pub(crate) mod test { assert_to_name(&Name::from_octets(b"\0").unwrap()); assert_to_name(&Name::from_octets(b"\0".as_ref()).unwrap()); - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] { assert_to_name( &Name::from_octets(Vec::from(b"\0".as_ref())).unwrap(), @@ -1265,7 +1265,7 @@ pub(crate) mod test { #[test] fn root() { assert_eq!(Name::root_ref().as_slice(), b"\0"); - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] { assert_eq!(Name::root_vec().as_slice(), b"\0"); } @@ -1279,7 +1279,7 @@ pub(crate) mod test { } #[test] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn from_slice() { // a simple good name assert_eq!( @@ -1310,7 +1310,7 @@ pub(crate) mod test { assert!(Name::from_slice(&slice[..]).is_err()); // name 255 long ok, 256 bad. - let mut buf = std::vec::Vec::new(); + let mut buf = alloc::vec::Vec::new(); for _ in 0..25 { buf.extend_from_slice(b"\x09123456789"); } @@ -1383,7 +1383,7 @@ pub(crate) mod test { } #[test] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn make_canonical() { let mut name = RelativeName::vec_from_str("wWw.exAmpLE.coM").unwrap(); name.make_canonical(); @@ -1798,7 +1798,7 @@ pub(crate) mod test { } #[test] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn parse() { // Parse a correctly formatted name. let mut p = Parser::from_static(b"\x03www\x07example\x03com\0af"); @@ -1857,7 +1857,7 @@ pub(crate) mod test { // copies the underlying bytes. #[test] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn compose_canonical() { use octseq::builder::infallible; @@ -1871,14 +1871,14 @@ pub(crate) mod test { } #[test] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn from_str() { // Another simple test. `NameBuilder` does all the heavy lifting, // so we don’t need to test all the escape sequence shenanigans here. // Just check that we’ll always get a name, final dot or not, unless // the string is empty. + use alloc::vec::Vec; use core::str::FromStr; - use std::vec::Vec; assert_eq!(Name::>::from_str(".").unwrap().as_slice(), b"\0"); assert_eq!( @@ -1997,9 +1997,9 @@ pub(crate) mod test { // Scan skipped for now. #[test] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn display() { - use std::string::ToString; + use alloc::string::ToString; fn cmp(bytes: &[u8], fmt: &str, fmt_with_dot: &str) { let name = Name::from_octets(bytes).unwrap(); @@ -2012,7 +2012,7 @@ pub(crate) mod test { cmp(b"\x07example\x03com\0", "example.com", "example.com."); } - #[cfg(all(feature = "serde", feature = "std"))] + #[cfg(all(feature = "serde", feature = "alloc"))] #[test] fn ser_de() { use serde_test::{assert_tokens, Configure, Token}; diff --git a/src/base/name/builder.rs b/src/base/name/builder.rs index 77f73d3e5..02ebc5460 100644 --- a/src/base/name/builder.rs +++ b/src/base/name/builder.rs @@ -8,12 +8,12 @@ use super::absolute::Name; use super::relative::{RelativeName, RelativeNameError}; use super::traits::{ToName, ToRelativeName}; use super::Label; +#[cfg(feature = "alloc")] +use alloc::vec::Vec; #[cfg(feature = "bytes")] use bytes::BytesMut; use core::fmt; use octseq::builder::{EmptyBuilder, FreezeBuilder, OctetsBuilder, ShortBuf}; -#[cfg(feature = "std")] -use std::vec::Vec; //------------ NameBuilder -------------------------------------------------- @@ -92,7 +92,7 @@ impl NameBuilder { } } -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] impl NameBuilder> { /// Creates an empty domain name builder atop a `Vec`. #[must_use] @@ -762,7 +762,7 @@ impl core::error::Error for PresentationError {} //============ Testing ======================================================= #[cfg(test)] -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod test { use super::*; diff --git a/src/base/name/chain.rs b/src/base/name/chain.rs index a9f8cb3f8..ee40160ab 100644 --- a/src/base/name/chain.rs +++ b/src/base/name/chain.rs @@ -378,7 +378,7 @@ impl core::error::Error for LongChainError {} //============ Testing ======================================================= #[cfg(test)] -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod test { use super::*; use crate::base::name::RelativeName; @@ -387,7 +387,7 @@ mod test { /// Tests that `ToName` and `ToRelativeName` are implemented for the /// right types. #[test] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn impls() { fn assert_to_name(_: &T) {} fn assert_to_relative_name(_: &T) {} @@ -531,7 +531,7 @@ mod test { /// Tests that composing works as expected. #[test] fn compose() { - use std::vec::Vec; + use alloc::vec::Vec; let w = RelativeName::from_octets(b"\x03www".as_ref()).unwrap(); let ec = RelativeName::from_octets(b"\x07example\x03com".as_ref()) @@ -593,7 +593,7 @@ mod test { ) where Chain: ToLabelIter, { - use std::string::ToString; + use alloc::string::ToString; let chain = chain.unwrap(); assert_eq!(chain.to_string(), out); diff --git a/src/base/name/label.rs b/src/base/name/label.rs index 64d509e00..7baf33746 100644 --- a/src/base/name/label.rs +++ b/src/base/name/label.rs @@ -362,8 +362,8 @@ impl AsMut<[u8]> for Label { //--- ToOwned -#[cfg(feature = "std")] -impl std::borrow::ToOwned for Label { +#[cfg(feature = "alloc")] +impl alloc::borrow::ToOwned for Label { type Owned = OwnedLabel; fn to_owned(&self) -> Self::Owned { @@ -947,10 +947,10 @@ mod test { } #[test] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn compose() { + use alloc::vec::Vec; use octseq::builder::infallible; - use std::vec::Vec; let mut buf = Vec::new(); infallible(Label::root().compose(&mut buf)); diff --git a/src/base/name/parsed.rs b/src/base/name/parsed.rs index 165bd0494..6a080469d 100644 --- a/src/base/name/parsed.rs +++ b/src/base/name/parsed.rs @@ -959,7 +959,7 @@ mod test { } #[test] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn split_first() { fn split_first_wec(mut name: ParsedName<&[u8]>) { assert_eq!( @@ -991,7 +991,7 @@ mod test { } #[test] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn parent() { fn parent_wec(mut name: ParsedName<&[u8]>) { assert_eq!( @@ -1014,9 +1014,9 @@ mod test { } #[test] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn parse_and_skip() { - use std::vec::Vec; + use alloc::vec::Vec; fn name_eq(parsed: ParsedName<&[u8]>, name: ParsedName<&[u8]>) { assert_eq!(parsed.octets, name.octets); @@ -1144,10 +1144,10 @@ mod test { } #[test] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn compose() { + use alloc::vec::Vec; use octseq::builder::infallible; - use std::vec::Vec; fn step(name: ParsedName<&[u8]>, result: &[u8]) { let mut buf = Vec::new(); diff --git a/src/base/name/relative.rs b/src/base/name/relative.rs index 495d668ea..4af41df17 100644 --- a/src/base/name/relative.rs +++ b/src/base/name/relative.rs @@ -8,6 +8,8 @@ use super::builder::{FromStrError, NameBuilder, PushError}; use super::chain::{Chain, LongChainError}; use super::label::{Label, LabelTypeError, SplitLabelError}; use super::traits::{ToLabelIter, ToRelativeName}; +#[cfg(feature = "alloc")] +use alloc::vec::Vec; #[cfg(feature = "bytes")] use bytes::Bytes; use core::cmp::Ordering; @@ -20,8 +22,6 @@ use octseq::builder::{ use octseq::octets::{Octets, OctetsFrom}; #[cfg(feature = "serde")] use octseq::serde::{DeserializeOctets, SerializeOctets}; -#[cfg(feature = "std")] -use std::vec::Vec; //------------ RelativeName -------------------------------------------------- @@ -217,7 +217,7 @@ impl RelativeName<&'static [u8]> { } } -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] impl RelativeName> { /// Creates an empty relative name atop a `Vec`. #[must_use] @@ -873,10 +873,10 @@ where }) } - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn visit_byte_buf( self, - value: std::vec::Vec, + value: alloc::vec::Vec, ) -> Result { self.0.visit_byte_buf(value).and_then(|octets| { RelativeName::from_octets(octets).map_err(E::custom) @@ -1111,7 +1111,7 @@ mod test { } #[test] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn impls() { fn assert_to_relative_name(_: &T) {} @@ -1146,7 +1146,7 @@ mod test { assert_eq!(RelativeName::empty_slice().as_slice(), b""); assert_eq!(RelativeName::empty_ref().as_slice(), b""); - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] { assert_eq!(RelativeName::empty_vec().as_slice(), b""); } @@ -1157,7 +1157,7 @@ mod test { assert_eq!(RelativeName::wildcard_slice().as_slice(), b"\x01*"); assert_eq!(RelativeName::wildcard_ref().as_slice(), b"\x01*"); - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] { assert_eq!(RelativeName::wildcard_vec().as_slice(), b"\x01*"); } @@ -1171,7 +1171,7 @@ mod test { } #[test] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn from_slice() { // good names assert_eq!(RelativeName::from_slice(b"").unwrap().as_slice(), b""); @@ -1238,7 +1238,7 @@ mod test { } #[test] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn from_str() { // empty name assert_eq!(RelativeName::vec_from_str("").unwrap().as_slice(), b""); @@ -1256,7 +1256,7 @@ mod test { } #[test] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn into_absolute() { assert_eq!( RelativeName::from_octets(Vec::from( @@ -1284,7 +1284,7 @@ mod test { } #[test] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn make_canonical() { let mut name = Name::vec_from_str("wWw.exAmpLE.coM.").unwrap(); name.make_canonical(); @@ -1777,9 +1777,9 @@ mod test { } #[test] - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn display() { - use std::string::ToString; + use alloc::string::ToString; fn cmp(bytes: &[u8], fmt: &str) { let name = RelativeName::from_octets(bytes).unwrap(); @@ -1816,7 +1816,7 @@ mod test { assert_eq!(INVALID_NAME, RelativeNameErrorEnum::AbsoluteName.into()); } - #[cfg(all(feature = "serde", feature = "std"))] + #[cfg(all(feature = "serde", feature = "alloc"))] #[test] fn ser_de() { use serde_test::{assert_tokens, Configure, Token}; diff --git a/src/base/name/traits.rs b/src/base/name/traits.rs index dc58fbe19..f99430ebc 100644 --- a/src/base/name/traits.rs +++ b/src/base/name/traits.rs @@ -6,6 +6,8 @@ use super::absolute::Name; use super::chain::{Chain, LongChainError}; use super::label::Label; use super::relative::RelativeName; +#[cfg(feature = "alloc")] +use alloc::borrow::Cow; #[cfg(feature = "bytes")] use bytes::Bytes; use core::convert::Infallible; @@ -14,8 +16,6 @@ use octseq::builder::{ infallible, BuilderAppendError, EmptyBuilder, FreezeBuilder, FromBuilder, OctetsBuilder, ShortBuf, }; -#[cfg(feature = "std")] -use std::borrow::Cow; //------------ ToLabelIter --------------------------------------------------- @@ -215,8 +215,8 @@ pub trait ToName: ToLabelIter { /// /// [`as_flat_slice`]: ToName::as_flat_slice /// [`to_name`]: ToName::to_name - #[cfg(feature = "std")] - fn to_cow(&self) -> Name> { + #[cfg(feature = "alloc")] + fn to_cow(&self) -> Name> { let octets = self .as_flat_slice() .map(Cow::Borrowed) @@ -225,8 +225,8 @@ pub trait ToName: ToLabelIter { } /// Returns the domain name assembled into a `Vec`. - #[cfg(feature = "std")] - fn to_vec(&self) -> Name> { + #[cfg(feature = "alloc")] + fn to_vec(&self) -> Name> { self.to_name() } @@ -501,8 +501,8 @@ pub trait ToRelativeName: ToLabelIter { /// /// [`as_flat_slice`]: ToRelativeName::as_flat_slice /// [`to_relative_name`]: ToRelativeName::to_relative_name - #[cfg(feature = "std")] - fn to_cow(&self) -> RelativeName> { + #[cfg(feature = "alloc")] + fn to_cow(&self) -> RelativeName> { let octets = self .as_flat_slice() .map(Cow::Borrowed) @@ -511,8 +511,8 @@ pub trait ToRelativeName: ToLabelIter { } /// Returns the domain name assembled into a `Vec`. - #[cfg(feature = "std")] - fn to_vec(&self) -> RelativeName> { + #[cfg(feature = "alloc")] + fn to_vec(&self) -> RelativeName> { self.to_relative_name() } diff --git a/src/base/name/uncertain.rs b/src/base/name/uncertain.rs index 00c0cd8e0..a33094bee 100644 --- a/src/base/name/uncertain.rs +++ b/src/base/name/uncertain.rs @@ -10,6 +10,8 @@ use super::chain::{Chain, LongChainError}; use super::label::{Label, LabelTypeError, SplitLabelError}; use super::relative::{NameIter, RelativeName}; use super::traits::ToLabelIter; +#[cfg(feature = "alloc")] +use alloc::vec::Vec; #[cfg(feature = "bytes")] use bytes::Bytes; use core::{fmt, hash, str}; @@ -18,8 +20,6 @@ use octseq::builder::{ }; #[cfg(feature = "serde")] use octseq::serde::{DeserializeOctets, SerializeOctets}; -#[cfg(feature = "std")] -use std::vec::Vec; //------------ UncertainName ------------------------------------------------ @@ -163,7 +163,7 @@ impl UncertainName<&'static [u8]> { } } -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] impl UncertainName> { /// Creates an empty relative name atop a `Vec`. #[must_use] @@ -509,10 +509,10 @@ where }) } - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn visit_byte_buf( self, - value: std::vec::Vec, + value: alloc::vec::Vec, ) -> Result { self.0.visit_byte_buf(value).and_then(|octets| { UncertainName::from_octets(octets).map_err(E::custom) @@ -642,11 +642,11 @@ impl core::error::Error for UncertainDnameError {} //============ Testing ======================================================= #[cfg(test)] -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod test { use super::*; - use std::str::FromStr; - use std::string::String; + use alloc::string::String; + use core::str::FromStr; #[test] fn from_str() { diff --git a/src/base/net/nostd.rs b/src/base/net/nostd.rs index 1892c4ad3..1f664fdbd 100644 --- a/src/base/net/nostd.rs +++ b/src/base/net/nostd.rs @@ -56,7 +56,7 @@ impl<'de> serde::Deserialize<'de> for Ipv4Addr { impl<'de> serde::de::Visitor<'de> for Visitor { type Value = Ipv4Addr; - fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn expecting(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("an IPv4 address") } @@ -250,7 +250,7 @@ impl<'de> serde::Deserialize<'de> for Ipv6Addr { impl<'de> serde::de::Visitor<'de> for Visitor { type Value = Ipv6Addr; - fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn expecting(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("an IPv6 address") } diff --git a/src/base/opt/algsig.rs b/src/base/opt/algsig.rs index e3c0acf2f..e7c0a39ba 100644 --- a/src/base/opt/algsig.rs +++ b/src/base/opt/algsig.rs @@ -565,7 +565,7 @@ impl Iterator for SecurityAlgorithmIter<'_> { //============ Tests ======================================================== #[cfg(test)] -#[cfg(all(feature = "std", feature = "bytes"))] +#[cfg(all(feature = "alloc", feature = "bytes"))] mod test { use super::super::test::test_option_compose_parse; use super::*; diff --git a/src/base/opt/chain.rs b/src/base/opt/chain.rs index 82a12c03d..485548839 100644 --- a/src/base/opt/chain.rs +++ b/src/base/opt/chain.rs @@ -217,12 +217,12 @@ impl OptBuilder<'_, Target> { //============ Testing ====================================================== #[cfg(test)] -#[cfg(all(feature = "std", feature = "bytes"))] +#[cfg(all(feature = "alloc", feature = "bytes"))] mod test { use super::super::test::test_option_compose_parse; use super::*; + use alloc::vec::Vec; use core::str::FromStr; - use std::vec::Vec; #[test] #[allow(clippy::redundant_closure)] // lifetimes ... diff --git a/src/base/opt/expire.rs b/src/base/opt/expire.rs index 3dafb288f..6be930f79 100644 --- a/src/base/opt/expire.rs +++ b/src/base/opt/expire.rs @@ -145,7 +145,7 @@ impl OptBuilder<'_, Target> { //============ Testing ====================================================== #[cfg(test)] -#[cfg(all(feature = "std", feature = "bytes"))] +#[cfg(all(feature = "alloc", feature = "bytes"))] mod test { use super::super::test::test_option_compose_parse; use super::*; diff --git a/src/base/opt/exterr.rs b/src/base/opt/exterr.rs index cf91e9179..cf412cbbb 100644 --- a/src/base/opt/exterr.rs +++ b/src/base/opt/exterr.rs @@ -421,7 +421,7 @@ impl> fmt::Display for LossyOctets { //============ Tests ========================================================= -#[cfg(all(test, feature = "std", feature = "bytes"))] +#[cfg(all(test, feature = "alloc", feature = "bytes"))] mod tests { use super::super::test::test_option_compose_parse; use super::*; @@ -451,7 +451,7 @@ mod tests { #[test] fn display_lossy_octets() { - use std::string::ToString; + use alloc::string::ToString; assert_eq!(LossyOctets(b"foo").to_string(), "foo"); assert_eq!(LossyOctets(b"foo\xe7").to_string(), "foo\u{fffd}"); diff --git a/src/base/opt/keepalive.rs b/src/base/opt/keepalive.rs index 1504c0b3f..8b05f03eb 100644 --- a/src/base/opt/keepalive.rs +++ b/src/base/opt/keepalive.rs @@ -232,7 +232,7 @@ impl core::error::Error for FromDurationError {} //============ Testing ======================================================= #[cfg(test)] -#[cfg(all(feature = "std", feature = "bytes"))] +#[cfg(all(feature = "alloc", feature = "bytes"))] mod test { use super::super::test::test_option_compose_parse; use super::*; diff --git a/src/base/opt/keytag.rs b/src/base/opt/keytag.rs index d5b8c58f5..9952f55aa 100644 --- a/src/base/opt/keytag.rs +++ b/src/base/opt/keytag.rs @@ -385,7 +385,7 @@ impl Iterator for KeyTagIter<'_> { //============ Testing ====================================================== #[cfg(test)] -#[cfg(all(feature = "std", feature = "bytes"))] +#[cfg(all(feature = "alloc", feature = "bytes"))] mod test { use super::super::test::test_option_compose_parse; use super::*; diff --git a/src/base/opt/mod.rs b/src/base/opt/mod.rs index a1fba611f..b30bcb661 100644 --- a/src/base/opt/mod.rs +++ b/src/base/opt/mod.rs @@ -1159,16 +1159,16 @@ impl core::error::Error for BuildDataError {} //============ Tests ========================================================= #[cfg(test)] -#[cfg(all(feature = "std", feature = "bytes"))] +#[cfg(all(feature = "alloc", feature = "bytes"))] pub(super) mod test { use super::*; use crate::base::rdata::test::{test_compose_parse, test_rdlen}; use crate::base::record::ParsedRecord; use crate::base::{opt, MessageBuilder}; + use alloc::vec::Vec; use bytes::{Bytes, BytesMut}; use core::fmt::Debug; use octseq::builder::infallible; - use std::vec::Vec; #[test] #[allow(clippy::redundant_closure)] // lifetimes ... diff --git a/src/base/opt/nsid.rs b/src/base/opt/nsid.rs index 06866e171..43e5fc23d 100644 --- a/src/base/opt/nsid.rs +++ b/src/base/opt/nsid.rs @@ -319,7 +319,7 @@ impl OptBuilder<'_, Target> { //============ Testing ====================================================== #[cfg(test)] -#[cfg(all(feature = "std", feature = "bytes"))] +#[cfg(all(feature = "alloc", feature = "bytes"))] mod test { use super::super::test::test_option_compose_parse; use super::*; diff --git a/src/base/opt/subnet.rs b/src/base/opt/subnet.rs index f5bbe5ddb..c60308227 100644 --- a/src/base/opt/subnet.rs +++ b/src/base/opt/subnet.rs @@ -367,13 +367,13 @@ fn normalize_prefix_len(addr: IpAddr, len: u8) -> u8 { //============ Testing ======================================================= -#[cfg(all(test, feature = "std", feature = "bytes"))] +#[cfg(all(test, feature = "alloc", feature = "bytes"))] mod tests { use super::super::test::test_option_compose_parse; use super::*; + use alloc::vec::Vec; use core::str::FromStr; use octseq::builder::infallible; - use std::vec::Vec; macro_rules! check { ($name:ident, $addr:expr, $prefix:expr, $exp:expr, $ok:expr) => { diff --git a/src/base/rdata.rs b/src/base/rdata.rs index 0a0fd29a8..676046714 100644 --- a/src/base/rdata.rs +++ b/src/base/rdata.rs @@ -540,14 +540,14 @@ impl core::error::Error for LongRecordData {} //============ Testing ====================================================== #[cfg(test)] -#[cfg(all(feature = "std", feature = "bytes"))] +#[cfg(all(feature = "alloc", feature = "bytes"))] pub(crate) mod test { use super::super::scan::IterScanner; use super::*; + use alloc::vec::Vec; use bytes::{Bytes, BytesMut}; use core::fmt::Debug; use octseq::builder::infallible; - use std::vec::Vec; /// Check that `rdlen` produces the correct length. /// diff --git a/src/base/wire.rs b/src/base/wire.rs index fa3cfd035..9b750c14e 100644 --- a/src/base/wire.rs +++ b/src/base/wire.rs @@ -35,8 +35,8 @@ pub trait Composer: } } -#[cfg(feature = "std")] -impl Composer for std::vec::Vec {} +#[cfg(feature = "alloc")] +impl Composer for alloc::vec::Vec {} impl Composer for octseq::array::Array {} @@ -267,7 +267,7 @@ impl<'a, Octs: AsRef<[u8]> + ?Sized, const N: usize> Parse<'a, Octs> /// The actual parsing happens in the provided closure. Returns an error if /// the closure returns an error or if there is unparsed data left over after /// the closure returns. Otherwise returns whatever the closure returned. -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] pub fn parse_slice(data: &[u8], op: F) -> Result where F: FnOnce(&mut Parser<'_, [u8]>) -> Result, @@ -286,13 +286,13 @@ where /// The actual composing happens in the provided closure. /// This function is mostly useful in testing so you can construct this vec /// directly inside an asserting. -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] pub fn compose_vec( op: impl FnOnce( - &mut std::vec::Vec, + &mut alloc::vec::Vec, ) -> Result<(), core::convert::Infallible>, -) -> std::vec::Vec { - let mut res = std::vec::Vec::new(); +) -> alloc::vec::Vec { + let mut res = alloc::vec::Vec::new(); octseq::builder::infallible(op(&mut res)); res } diff --git a/src/base/zonefile_fmt.rs b/src/base/zonefile_fmt.rs index a137e6392..3f92fcd34 100644 --- a/src/base/zonefile_fmt.rs +++ b/src/base/zonefile_fmt.rs @@ -314,10 +314,10 @@ pub trait Formatter: FormatWriter { impl Formatter for T {} -#[cfg(all(test, feature = "std"))] +#[cfg(all(test, feature = "alloc"))] mod test { - use std::string::ToString as _; - use std::vec::Vec; + use alloc::string::ToString as _; + use alloc::vec::Vec; use crate::base::iana::{Class, DigestAlgorithm, SecurityAlgorithm}; use crate::base::zonefile_fmt::{DisplayKind, ZonefileFmt}; diff --git a/src/lib.rs b/src/lib.rs index 22c4f55bd..8e997e9de 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -186,6 +186,8 @@ #![cfg_attr(docsrs, feature(doc_cfg))] #[cfg(feature = "alloc")] +#[allow(unused_imports)] // Import macros even if unused. +#[macro_use] extern crate alloc; #[cfg(feature = "std")] diff --git a/src/rdata/aaaa.rs b/src/rdata/aaaa.rs index 9fae53437..1c37d1657 100644 --- a/src/rdata/aaaa.rs +++ b/src/rdata/aaaa.rs @@ -182,7 +182,7 @@ impl AsMut for Aaaa { //============ Testing ====================================================== #[cfg(test)] -#[cfg(all(feature = "std", feature = "bytes"))] +#[cfg(all(feature = "alloc", feature = "bytes"))] mod test { use super::*; use crate::base::rdata::test::{ diff --git a/src/rdata/caa.rs b/src/rdata/caa.rs index 4e79b5d0e..3a268835b 100644 --- a/src/rdata/caa.rs +++ b/src/rdata/caa.rs @@ -621,11 +621,11 @@ impl<'a, Octs: AsRef<[u8]> + ?Sized> Parse<'a, Octs> for CaaFlags { } #[cfg(test)] -#[cfg(all(feature = "std", feature = "bytes"))] +#[cfg(all(feature = "alloc", feature = "bytes"))] mod test { use super::*; + use alloc::string::ToString; use octseq::array::Array; - use std::string::ToString; #[test] fn caa_eq() { diff --git a/src/rdata/cds.rs b/src/rdata/cds.rs index 98908a29f..12b7d731f 100644 --- a/src/rdata/cds.rs +++ b/src/rdata/cds.rs @@ -703,7 +703,7 @@ pub mod parsed { //============ Test ========================================================== #[cfg(test)] -#[cfg(all(feature = "std", feature = "bytes"))] +#[cfg(all(feature = "alloc", feature = "bytes"))] mod test { use super::*; use crate::base::rdata::test::{ diff --git a/src/rdata/dname.rs b/src/rdata/dname.rs index bb420576f..f61dce985 100644 --- a/src/rdata/dname.rs +++ b/src/rdata/dname.rs @@ -22,15 +22,15 @@ name_type_canonical! { //============ Testing ====================================================== #[cfg(test)] -#[cfg(all(feature = "std", feature = "bytes"))] +#[cfg(all(feature = "alloc", feature = "bytes"))] mod test { use super::*; use crate::base::name::Name; use crate::base::rdata::test::{ test_compose_parse, test_rdlen, test_scan, }; + use alloc::vec::Vec; use core::str::FromStr; - use std::vec::Vec; #[test] fn create_dname() { diff --git a/src/rdata/dnssec.rs b/src/rdata/dnssec.rs index 22fd2c034..9d3d9d12a 100644 --- a/src/rdata/dnssec.rs +++ b/src/rdata/dnssec.rs @@ -16,6 +16,8 @@ use crate::base::wire::{Compose, Composer, FormError, Parse, ParseError}; use crate::base::zonefile_fmt::{self, Formatter, ZonefileFmt}; use crate::base::Ttl; use crate::utils::{base16, base64}; +#[cfg(feature = "alloc")] +use alloc::vec::Vec; use core::cmp::Ordering; use core::convert::TryInto; use core::{cmp, fmt, hash, str}; @@ -28,8 +30,6 @@ use octseq::parse::Parser; use octseq::serde::{DeserializeOctets, SerializeOctets}; #[cfg(feature = "std")] use std::time::{Duration, SystemTime, UNIX_EPOCH}; -#[cfg(feature = "std")] -use std::vec::Vec; //------------ Dnskey -------------------------------------------------------- @@ -2383,10 +2383,10 @@ where }) } - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn visit_byte_buf( self, - value: std::vec::Vec, + value: alloc::vec::Vec, ) -> Result { self.0.visit_byte_buf(value).and_then(|octets| { RtypeBitmap::from_octets(octets).map_err(E::custom) @@ -2467,7 +2467,7 @@ impl RtypeBitmapBuilder { } } -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] impl RtypeBitmapBuilder> { #[must_use] pub fn new_vec() -> Self { @@ -2727,7 +2727,7 @@ impl core::error::Error for IllegalSignatureTime {} //============ Test ========================================================== #[cfg(test)] -#[cfg(all(feature = "std", feature = "bytes"))] +#[cfg(all(feature = "alloc", feature = "bytes"))] mod test { use super::*; use crate::base::iana::Rtype; @@ -2735,8 +2735,8 @@ mod test { use crate::base::rdata::test::{ test_compose_parse, test_rdlen, test_scan, }; + use alloc::vec::Vec; use core::str::FromStr; - use std::vec::Vec; //--- Dnskey @@ -2880,7 +2880,7 @@ mod test { #[test] fn rtype_bitmap_iter() { - use std::vec::Vec; + use alloc::vec::Vec; let mut builder = RtypeBitmapBuilder::new_vec(); let types = vec![ diff --git a/src/rdata/ipseckey.rs b/src/rdata/ipseckey.rs index 435b3bbc2..2ff207e58 100644 --- a/src/rdata/ipseckey.rs +++ b/src/rdata/ipseckey.rs @@ -680,7 +680,7 @@ impl fmt::Debug for IpseckeyGateway { } #[cfg(test)] -#[cfg(all(feature = "std", feature = "bytes"))] +#[cfg(all(feature = "alloc", feature = "bytes"))] mod test { use super::*; use crate::base::rdata::test::{ @@ -688,10 +688,10 @@ mod test { }; use crate::base::Name; use crate::utils::base64::decode; + use alloc::string::ToString; + use alloc::vec::Vec; use core::str::FromStr; use std::net::{Ipv4Addr, Ipv6Addr}; - use std::string::ToString; - use std::vec::Vec; #[test] // allow redundant_closure because of lifetime shenanigans diff --git a/src/rdata/naptr.rs b/src/rdata/naptr.rs index 0c103889e..acfa48900 100644 --- a/src/rdata/naptr.rs +++ b/src/rdata/naptr.rs @@ -509,7 +509,7 @@ where //============ Testing ======================================================= #[cfg(test)] -#[cfg(all(feature = "std", feature = "bytes"))] +#[cfg(all(feature = "alloc", feature = "bytes"))] mod test { use bytes::Bytes; @@ -518,8 +518,8 @@ mod test { rdata::test::{test_compose_parse, test_rdlen, test_scan}, Name, }; + use alloc::vec::Vec; use core::str::FromStr; - use std::vec::Vec; #[test] #[allow(clippy::redundant_closure)] // lifetimes ... diff --git a/src/rdata/nsec3.rs b/src/rdata/nsec3.rs index e28b5712d..efcd89baa 100644 --- a/src/rdata/nsec3.rs +++ b/src/rdata/nsec3.rs @@ -1208,10 +1208,10 @@ where }) } - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn visit_byte_buf( self, - value: std::vec::Vec, + value: alloc::vec::Vec, ) -> Result { self.0.visit_byte_buf(value).and_then(|octets| { Nsec3Salt::from_octets(octets).map_err(E::custom) @@ -1583,10 +1583,10 @@ where }) } - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn visit_byte_buf( self, - value: std::vec::Vec, + value: alloc::vec::Vec, ) -> Result { self.0.visit_byte_buf(value).and_then(|octets| { OwnerHash::from_octets(octets).map_err(E::custom) @@ -1667,7 +1667,7 @@ impl core::error::Error for OwnerHashError {} //============ Testing ====================================================== #[cfg(test)] -#[cfg(all(feature = "std", feature = "bytes"))] +#[cfg(all(feature = "alloc", feature = "bytes"))] mod test { use super::super::dnssec::RtypeBitmapBuilder; use super::*; @@ -1675,7 +1675,7 @@ mod test { test_compose_parse, test_rdlen, test_scan, }; use crate::base::zonefile_fmt::DisplayKind; - use std::vec::Vec; + use alloc::vec::Vec; #[test] #[allow(clippy::redundant_closure)] // lifetimes ... diff --git a/src/rdata/openpgpkey.rs b/src/rdata/openpgpkey.rs index a54535d63..ed637b5f3 100644 --- a/src/rdata/openpgpkey.rs +++ b/src/rdata/openpgpkey.rs @@ -186,14 +186,14 @@ impl> Ord for Openpgpkey { } #[cfg(test)] -#[cfg(all(feature = "std", feature = "bytes"))] +#[cfg(all(feature = "alloc", feature = "bytes"))] mod test { use super::*; use crate::base::rdata::test::{ test_compose_parse, test_rdlen, test_scan, }; use crate::utils::base64::decode; - use std::vec::Vec; + use alloc::vec::Vec; #[test] // allow redundant_closure because because of lifetime shenanigans diff --git a/src/rdata/rfc1035/a.rs b/src/rdata/rfc1035/a.rs index 6e0268a78..4cbb3d582 100644 --- a/src/rdata/rfc1035/a.rs +++ b/src/rdata/rfc1035/a.rs @@ -196,7 +196,7 @@ impl AsMut for A { //============ Testing ======================================================= #[cfg(test)] -#[cfg(all(feature = "std", feature = "bytes"))] +#[cfg(all(feature = "alloc", feature = "bytes"))] mod test { use super::*; use crate::base::rdata::test::{ diff --git a/src/rdata/rfc1035/hinfo.rs b/src/rdata/rfc1035/hinfo.rs index e620e5d13..128c6aef8 100644 --- a/src/rdata/rfc1035/hinfo.rs +++ b/src/rdata/rfc1035/hinfo.rs @@ -256,13 +256,13 @@ impl> ZonefileFmt for Hinfo { //============ Testing ======================================================= #[cfg(test)] -#[cfg(all(feature = "std", feature = "bytes"))] +#[cfg(all(feature = "alloc", feature = "bytes"))] mod test { use super::*; use crate::base::rdata::test::{ test_compose_parse, test_rdlen, test_scan, }; - use std::vec::Vec; + use alloc::vec::Vec; #[test] #[allow(clippy::redundant_closure)] // lifetimes ... diff --git a/src/rdata/rfc1035/minfo.rs b/src/rdata/rfc1035/minfo.rs index 894305bbc..c3e84e1e7 100644 --- a/src/rdata/rfc1035/minfo.rs +++ b/src/rdata/rfc1035/minfo.rs @@ -259,15 +259,15 @@ impl ZonefileFmt for Minfo { //============ Testing ======================================================= #[cfg(test)] -#[cfg(all(feature = "std", feature = "bytes"))] +#[cfg(all(feature = "alloc", feature = "bytes"))] mod test { use super::*; use crate::base::name::Name; use crate::base::rdata::test::{ test_compose_parse, test_rdlen, test_scan, }; + use alloc::vec::Vec; use core::str::FromStr; - use std::vec::Vec; #[test] #[allow(clippy::redundant_closure)] // lifetimes ... diff --git a/src/rdata/rfc1035/mx.rs b/src/rdata/rfc1035/mx.rs index 649e49f4d..a5be67e0e 100644 --- a/src/rdata/rfc1035/mx.rs +++ b/src/rdata/rfc1035/mx.rs @@ -243,15 +243,15 @@ impl ZonefileFmt for Mx { //============ Testing ======================================================= #[cfg(test)] -#[cfg(all(feature = "std", feature = "bytes"))] +#[cfg(all(feature = "alloc", feature = "bytes"))] mod test { use super::*; use crate::base::name::Name; use crate::base::rdata::test::{ test_compose_parse, test_rdlen, test_scan, }; + use alloc::vec::Vec; use core::str::FromStr; - use std::vec::Vec; #[test] #[allow(clippy::redundant_closure)] // lifetimes ... diff --git a/src/rdata/rfc1035/name.rs b/src/rdata/rfc1035/name.rs index 8ef505e1b..8a3711e14 100644 --- a/src/rdata/rfc1035/name.rs +++ b/src/rdata/rfc1035/name.rs @@ -134,14 +134,14 @@ name_type_well_known! { //============ Testing ======================================================= #[cfg(test)] -#[cfg(all(feature = "std", feature = "bytes"))] +#[cfg(all(feature = "alloc", feature = "bytes"))] mod test { use super::*; use crate::base::name::Name; use crate::base::rdata::test::{ test_compose_parse, test_rdlen, test_scan, }; - use std::vec::Vec; + use alloc::vec::Vec; // We only test Cname since all the other types are exactly the same. diff --git a/src/rdata/rfc1035/null.rs b/src/rdata/rfc1035/null.rs index c2897c60e..c538b6477 100644 --- a/src/rdata/rfc1035/null.rs +++ b/src/rdata/rfc1035/null.rs @@ -305,7 +305,7 @@ impl> ZonefileFmt for Null { //============ Testing ======================================================= #[cfg(test)] -#[cfg(all(feature = "std", feature = "bytes"))] +#[cfg(all(feature = "alloc", feature = "bytes"))] mod test { use super::*; use crate::base::rdata::test::{test_compose_parse, test_rdlen}; diff --git a/src/rdata/rfc1035/soa.rs b/src/rdata/rfc1035/soa.rs index cb959ad8a..a0042e152 100644 --- a/src/rdata/rfc1035/soa.rs +++ b/src/rdata/rfc1035/soa.rs @@ -437,15 +437,15 @@ impl ZonefileFmt for Soa { //============ Testing ======================================================= #[cfg(test)] -#[cfg(all(feature = "std", feature = "bytes"))] +#[cfg(all(feature = "alloc", feature = "bytes"))] mod test { use super::*; use crate::base::name::Name; use crate::base::rdata::test::{ test_compose_parse, test_rdlen, test_scan, }; + use alloc::vec::Vec; use core::str::FromStr; - use std::vec::Vec; #[test] #[allow(clippy::redundant_closure)] // lifetimes ... diff --git a/src/rdata/rfc1035/txt.rs b/src/rdata/rfc1035/txt.rs index 452c804c2..18d2d6bdc 100644 --- a/src/rdata/rfc1035/txt.rs +++ b/src/rdata/rfc1035/txt.rs @@ -622,10 +622,10 @@ where }) } - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn visit_byte_buf( self, - value: std::vec::Vec, + value: alloc::vec::Vec, ) -> Result { self.0.visit_byte_buf(value).and_then(|octets| { Txt::from_octets(octets).map_err(E::custom) @@ -922,13 +922,13 @@ impl fmt::Display for TxtAppendError { //============ Testing ======================================================= #[cfg(test)] -#[cfg(all(feature = "std", feature = "bytes"))] +#[cfg(all(feature = "alloc", feature = "bytes"))] mod test { use super::*; use crate::base::rdata::test::{ test_compose_parse, test_rdlen, test_scan, }; - use std::vec::Vec; + use alloc::vec::Vec; #[test] #[allow(clippy::redundant_closure)] // lifetimes ... @@ -1057,7 +1057,7 @@ mod test { assert_eq!(records[0], records[2]); } - #[cfg(all(feature = "serde", feature = "std"))] + #[cfg(all(feature = "serde", feature = "alloc"))] #[test] fn txt_ser_de() { use serde_test::{assert_tokens, Configure, Token}; @@ -1104,7 +1104,7 @@ mod test { ); } - #[cfg(all(feature = "serde", feature = "std"))] + #[cfg(all(feature = "serde", feature = "alloc"))] #[test] fn txt_de_str() { use serde_test::{assert_de_tokens, Configure, Token}; diff --git a/src/rdata/rp.rs b/src/rdata/rp.rs index ad333c635..72b3a6305 100644 --- a/src/rdata/rp.rs +++ b/src/rdata/rp.rs @@ -256,7 +256,7 @@ impl ZonefileFmt for Rp { //============ Testing ======================================================= #[cfg(test)] -#[cfg(all(feature = "std", feature = "bytes"))] +#[cfg(all(feature = "alloc", feature = "bytes"))] mod test { use octseq::Array; @@ -267,8 +267,8 @@ mod test { test_compose_parse, test_rdlen, test_scan, }; use crate::zonefile::inplace::{self, Zonefile}; + use alloc::vec::Vec; use core::str::FromStr; - use std::vec::Vec; type Octets512 = Array<512>; diff --git a/src/rdata/srv.rs b/src/rdata/srv.rs index 4ed9c4caa..b7997c4bd 100644 --- a/src/rdata/srv.rs +++ b/src/rdata/srv.rs @@ -303,15 +303,15 @@ impl ZonefileFmt for Srv { //============ Testing ====================================================== #[cfg(test)] -#[cfg(all(feature = "std", feature = "bytes"))] +#[cfg(all(feature = "alloc", feature = "bytes"))] mod test { use super::*; use crate::base::name::Name; use crate::base::rdata::test::{ test_compose_parse, test_rdlen, test_scan, }; + use alloc::vec::Vec; use core::str::FromStr; - use std::vec::Vec; #[test] #[allow(clippy::redundant_closure)] // lifetimes ... diff --git a/src/rdata/sshfp.rs b/src/rdata/sshfp.rs index f30da0a73..5d590aabd 100644 --- a/src/rdata/sshfp.rs +++ b/src/rdata/sshfp.rs @@ -271,15 +271,15 @@ impl> Ord for Sshfp { } #[cfg(test)] -#[cfg(all(feature = "std", feature = "bytes"))] +#[cfg(all(feature = "alloc", feature = "bytes"))] mod test { use super::*; use crate::base::rdata::test::{ test_compose_parse, test_rdlen, test_scan, }; use crate::utils::base16::decode; - use std::string::ToString; - use std::vec::Vec; + use alloc::string::ToString; + use alloc::vec::Vec; #[test] // allow redundant_closure because because of lifetime shenanigans diff --git a/src/rdata/tlsa.rs b/src/rdata/tlsa.rs index 56eb950cf..03c73847d 100644 --- a/src/rdata/tlsa.rs +++ b/src/rdata/tlsa.rs @@ -299,15 +299,15 @@ impl> Ord for Tlsa { } #[cfg(test)] -#[cfg(all(feature = "std", feature = "bytes"))] +#[cfg(all(feature = "alloc", feature = "bytes"))] mod test { use super::*; use crate::base::rdata::test::{ test_compose_parse, test_rdlen, test_scan, }; use crate::utils::base16::decode; - use std::string::ToString; - use std::vec::Vec; + use alloc::string::ToString; + use alloc::vec::Vec; #[test] // allow redundant_closure because because of lifetime shenanigans diff --git a/src/rdata/tsig.rs b/src/rdata/tsig.rs index 62b022888..5520b2065 100644 --- a/src/rdata/tsig.rs +++ b/src/rdata/tsig.rs @@ -756,13 +756,13 @@ impl fmt::Display for Time48 { //============ Testing ======================================================= #[cfg(test)] -#[cfg(all(feature = "std", feature = "bytes"))] +#[cfg(all(feature = "alloc", feature = "bytes"))] mod test { use super::*; use crate::base::name::Name; use crate::base::rdata::test::{test_compose_parse, test_rdlen}; + use alloc::vec::Vec; use core::str::FromStr; - use std::vec::Vec; #[test] #[allow(clippy::redundant_closure)] // lifetimes ... diff --git a/src/rdata/zonemd.rs b/src/rdata/zonemd.rs index 947fa1c75..eecd02dda 100644 --- a/src/rdata/zonemd.rs +++ b/src/rdata/zonemd.rs @@ -302,15 +302,15 @@ impl> Ord for Zonemd { } #[cfg(test)] -#[cfg(all(feature = "std", feature = "bytes"))] +#[cfg(all(feature = "alloc", feature = "bytes"))] mod test { use super::*; use crate::base::rdata::test::{ test_compose_parse, test_rdlen, test_scan, }; use crate::utils::base16::decode; - use std::string::ToString; - use std::vec::Vec; + use alloc::string::ToString; + use alloc::vec::Vec; #[test] #[allow(clippy::redundant_closure)] // lifetimes ... diff --git a/src/utils/base16.rs b/src/utils/base16.rs index 743c3797f..784670978 100644 --- a/src/utils/base16.rs +++ b/src/utils/base16.rs @@ -11,12 +11,12 @@ //! [RFC 4648]: https://tools.ietf.org/html/rfc4648 use crate::base::scan::{ConvertSymbols, EntrySymbol, ScannerError}; +#[cfg(feature = "alloc")] +use alloc::string::String; use core::fmt; use octseq::builder::{ EmptyBuilder, FreezeBuilder, FromBuilder, OctetsBuilder, }; -#[cfg(feature = "std")] -use std::string::String; //------------ Re-exports ---------------------------------------------------- @@ -41,8 +41,8 @@ where } /// Decodes a string with Base 16 data and returns it as a vec. -#[cfg(feature = "std")] -pub fn decode_vec(s: &str) -> Result, DecodeError> { +#[cfg(feature = "alloc")] +pub fn decode_vec(s: &str) -> Result, DecodeError> { decode(s) } @@ -75,7 +75,7 @@ where } /// Encodes binary data in Base 16 and returns the encoded data as a string. -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] pub fn encode_string + ?Sized>(bytes: &B) -> String { let mut res = String::with_capacity(bytes.as_ref().len() * 2); display(bytes, &mut res).unwrap(); @@ -157,10 +157,10 @@ pub mod serde { self.0.visit_borrowed_bytes(value) } - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn visit_byte_buf( self, - value: std::vec::Vec, + value: alloc::vec::Vec, ) -> Result { self.0.visit_byte_buf(value) } @@ -355,7 +355,7 @@ const ENCODE_ALPHABET: [&str; 256] = [ //============ Test ========================================================== #[cfg(test)] -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod test { use super::*; @@ -364,7 +364,7 @@ mod test { fn decode_str() { use super::DecodeError; - fn decode(s: &str) -> Result, DecodeError> { + fn decode(s: &str) -> Result, DecodeError> { super::decode(s) } diff --git a/src/utils/base32.rs b/src/utils/base32.rs index 07460d8fc..c9df4aaa0 100644 --- a/src/utils/base32.rs +++ b/src/utils/base32.rs @@ -20,12 +20,12 @@ //! [NSEC3]: ../../rdata/rfc5155/index.html use crate::base::scan::{ConvertSymbols, EntrySymbol, ScannerError}; +#[cfg(feature = "alloc")] +use alloc::string::String; use core::fmt; use octseq::builder::{ EmptyBuilder, FreezeBuilder, FromBuilder, OctetsBuilder, }; -#[cfg(feature = "std")] -use std::string::String; //------------ Re-exports ---------------------------------------------------- @@ -105,7 +105,7 @@ where } /// Encodes binary data in *base32hex* and returns the encoded data as a string. -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] pub fn encode_string_hex + ?Sized>(bytes: &B) -> String { let mut res = String::with_capacity((bytes.as_ref().len() / 5 + 1) * 8); display_hex(bytes, &mut res).unwrap(); @@ -187,10 +187,10 @@ pub mod serde { self.0.visit_borrowed_bytes(value) } - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn visit_byte_buf( self, - value: std::vec::Vec, + value: alloc::vec::Vec, ) -> Result { self.0.visit_byte_buf(value) } @@ -521,7 +521,7 @@ const ENCODE_HEX_ALPHABET: [char; 32] = [ //============ Test ========================================================== #[cfg(test)] -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] mod test { use super::*; @@ -530,7 +530,7 @@ mod test { fn decode_str_hex() { use super::DecodeError; - fn decode_hex(s: &str) -> Result, DecodeError> { + fn decode_hex(s: &str) -> Result, DecodeError> { super::decode_hex(s) } diff --git a/src/utils/base64.rs b/src/utils/base64.rs index 09e3e75cb..de36607e4 100644 --- a/src/utils/base64.rs +++ b/src/utils/base64.rs @@ -13,12 +13,12 @@ //! [RFC 4648]: https://tools.ietf.org/html/rfc4648 use crate::base::scan::{ConvertSymbols, EntrySymbol, ScannerError}; +#[cfg(feature = "alloc")] +use alloc::string::String; use core::fmt; use octseq::builder::{ EmptyBuilder, FreezeBuilder, FromBuilder, OctetsBuilder, ShortBuf, }; -#[cfg(feature = "std")] -use std::string::String; //------------ Convenience Functions ----------------------------------------- @@ -91,7 +91,7 @@ where } /// Encodes binary data in *base64* and returns the encoded data as a string. -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] pub fn encode_string + ?Sized>(bytes: &B) -> String { let mut res = String::with_capacity((bytes.as_ref().len() / 3 + 1) * 4); display(bytes, &mut res).unwrap(); @@ -174,10 +174,10 @@ pub mod serde { self.0.visit_borrowed_bytes(value) } - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] fn visit_byte_buf( self, - value: std::vec::Vec, + value: alloc::vec::Vec, ) -> Result { self.0.visit_byte_buf(value) } @@ -518,7 +518,7 @@ const EOF_MARKER: usize = 0xF0; //============ Test ========================================================== -#[cfg(all(test, feature = "std"))] +#[cfg(all(test, feature = "alloc"))] mod test { use super::*; @@ -534,7 +534,7 @@ mod test { #[test] fn decode_str() { - fn decode(s: &str) -> Result, DecodeError> { + fn decode(s: &str) -> Result, DecodeError> { super::decode(s) } @@ -559,6 +559,7 @@ mod test { } #[test] + #[cfg(feature = "std")] fn symbol_converter() { use crate::base::scan::Symbols; use std::vec::Vec; diff --git a/src/utils/dst.rs b/src/utils/dst.rs index cc47a581a..5fea08b2c 100644 --- a/src/utils/dst.rs +++ b/src/utils/dst.rs @@ -313,12 +313,12 @@ pub trait UnsizedCopyFrom: Sized { fn unsized_copy_from(value: &Self::Source) -> Self; } -#[cfg(feature = "std")] -impl UnsizedCopyFrom for std::boxed::Box { +#[cfg(feature = "alloc")] +impl UnsizedCopyFrom for alloc::boxed::Box { type Source = T; fn unsized_copy_from(value: &Self::Source) -> Self { - use std::alloc; + use alloc::alloc; let layout = alloc::Layout::for_value(value); let ptr = unsafe { alloc::alloc(layout) }; @@ -328,12 +328,12 @@ impl UnsizedCopyFrom for std::boxed::Box { let src = value as *const _ as *const u8; unsafe { core::ptr::copy_nonoverlapping(src, ptr, layout.size()) }; let ptr = value.ptr_with_addr(ptr.cast()).cast_mut(); - unsafe { std::boxed::Box::from_raw(ptr) } + unsafe { ::alloc::boxed::Box::from_raw(ptr) } } } -#[cfg(feature = "std")] -impl UnsizedCopyFrom for std::rc::Rc { +#[cfg(feature = "alloc")] +impl UnsizedCopyFrom for alloc::rc::Rc { type Source = T; fn unsized_copy_from(value: &Self::Source) -> Self { @@ -348,24 +348,24 @@ impl UnsizedCopyFrom for std::rc::Rc { // 'impl FromIterator for Rc' describes performance characteristics. // For efficiency, the iterator should implement 'TrustedLen', which // is (currently) a nightly-only trait. However, we can use the - // existing 'std' types which happen to implement it. + // existing 'alloc' types which happen to implement it. let size = core::mem::size_of_val(value); - let rc: std::rc::Rc<[MaybeUninit>]> = + let rc: alloc::rc::Rc<[MaybeUninit>]> = (0..size).map(|_| MaybeUninit::uninit()).collect(); let src = value as *const _ as *const u8; - let dst = std::rc::Rc::into_raw(rc).cast_mut(); + let dst = alloc::rc::Rc::into_raw(rc).cast_mut(); // SAFETY: 'rc' was just constructed and has never been copied. Thus, // its contents can be mutated without violating any references. unsafe { core::ptr::copy_nonoverlapping(src, dst.cast(), size) }; let ptr = value.ptr_with_addr(dst.cast()); - unsafe { std::rc::Rc::from_raw(ptr) } + unsafe { alloc::rc::Rc::from_raw(ptr) } } } -#[cfg(feature = "std")] -impl UnsizedCopyFrom for std::sync::Arc { +#[cfg(feature = "alloc")] +impl UnsizedCopyFrom for alloc::sync::Arc { type Source = T; fn unsized_copy_from(value: &Self::Source) -> Self { @@ -380,24 +380,24 @@ impl UnsizedCopyFrom for std::sync::Arc { // 'impl FromIterator for Arc' describes performance characteristics. // For efficiency, the iterator should implement 'TrustedLen', which // is (currently) a nightly-only trait. However, we can use the - // existing 'std' types which happen to implement it. + // existing 'alloc' types which happen to implement it. let size = core::mem::size_of_val(value); - let arc: std::sync::Arc<[MaybeUninit>]> = + let arc: alloc::sync::Arc<[MaybeUninit>]> = (0..size).map(|_| MaybeUninit::uninit()).collect(); let src = value as *const _ as *const u8; - let dst = std::sync::Arc::into_raw(arc).cast_mut(); + let dst = alloc::sync::Arc::into_raw(arc).cast_mut(); // SAFETY: 'arc' was just constructed and has never been copied. Thus, // its contents can be mutated without violating any references. unsafe { core::ptr::copy_nonoverlapping(src, dst.cast(), size) }; let ptr = value.ptr_with_addr(dst.cast()); - unsafe { std::sync::Arc::from_raw(ptr) } + unsafe { alloc::sync::Arc::from_raw(ptr) } } } -#[cfg(feature = "std")] -impl UnsizedCopyFrom for std::vec::Vec { +#[cfg(feature = "alloc")] +impl UnsizedCopyFrom for alloc::vec::Vec { type Source = [T]; fn unsized_copy_from(value: &Self::Source) -> Self { @@ -415,8 +415,8 @@ impl UnsizedCopyFrom for std::vec::Vec { } } -#[cfg(feature = "std")] -impl UnsizedCopyFrom for std::string::String { +#[cfg(feature = "alloc")] +impl UnsizedCopyFrom for alloc::string::String { type Source = str; fn unsized_copy_from(value: &Self::Source) -> Self {