From c86e91babc1c9a4c4be18d1318c0283b9bc4f00a Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Mon, 18 Dec 2017 13:24:44 +0100 Subject: [PATCH] Deprecate some functions and minor tweaks --- Cargo.toml | 1 + rust-multiaddr/src/lib.rs | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 15026df4..7d39d670 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ members = [ "multistream-select", "datastore", "futures-mutex", + "rust-multiaddr", "rw-stream-sink", "circular-buffer", "varint-rs", diff --git a/rust-multiaddr/src/lib.rs b/rust-multiaddr/src/lib.rs index 80b5005d..df6b13d2 100644 --- a/rust-multiaddr/src/lib.rs +++ b/rust-multiaddr/src/lib.rs @@ -69,10 +69,12 @@ impl Multiaddr { /// ]); /// ``` /// + #[deprecated(note = "Use `string.parse()` instead")] pub fn new(input: &str) -> Result { let mut bytes = Vec::new(); let mut parts = input.split('/'); + // A multiaddr must start with `/` if !parts.next().ok_or(Error::InvalidMultiaddr)?.is_empty() { return Err(Error::InvalidMultiaddr); } @@ -119,6 +121,7 @@ impl Multiaddr { /// ``` /// #[inline] + #[deprecated(note = "Use `self.iter().map(|addr| addr.protocol_id())` instead")] pub fn protocol(&self) -> Vec { self.iter().map(|addr| addr.protocol_id()).collect() } @@ -144,7 +147,7 @@ impl Multiaddr { Ok(Multiaddr { bytes: bytes }) } - /// Remove the outer most address from itself. + /// Remove the outermost address. /// /// # Examples /// @@ -252,6 +255,16 @@ impl From for Multiaddr { } } +impl<'a> IntoIterator for &'a Multiaddr { + type Item = AddrComponent; + type IntoIter = Iter<'a>; + + #[inline] + fn into_iter(self) -> Iter<'a> { + Iter(&self.bytes) + } +} + impl FromIterator for Multiaddr { fn from_iter(iter: T) -> Self where T: IntoIterator