Deprecate some functions and minor tweaks

This commit is contained in:
Pierre Krieger 2017-12-18 13:24:44 +01:00
parent 458077417e
commit c86e91babc
2 changed files with 15 additions and 1 deletions

View File

@ -8,6 +8,7 @@ members = [
"multistream-select",
"datastore",
"futures-mutex",
"rust-multiaddr",
"rw-stream-sink",
"circular-buffer",
"varint-rs",

View File

@ -69,10 +69,12 @@ impl Multiaddr {
/// ]);
/// ```
///
#[deprecated(note = "Use `string.parse()` instead")]
pub fn new(input: &str) -> Result<Multiaddr> {
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<ProtocolId> {
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<AddrComponent> 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<AddrComponent> for Multiaddr {
fn from_iter<T>(iter: T) -> Self
where T: IntoIterator<Item = AddrComponent>