Skip to content

Commit

Permalink
Merge branch 'mxinden/master' into parity-multiaddr
Browse files Browse the repository at this point in the history
  • Loading branch information
mxinden committed May 20, 2021
2 parents 489e8ca + 9682623 commit 935a966
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
target
Cargo.lock
*.rs.bk
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[package]
name = "parity-multiaddr"
edition = "2018"
authors = ["dignifiedquire <[email protected]>", "Parity Technologies <[email protected]>"]
description = "Implementation of the multiaddr format"
homepage = "https://github.com/libp2p/rust-libp2p"
edition = "2018"
homepage = "https://github.com/multiformats/rust-multiaddr"
keywords = ["multiaddr", "ipfs"]
license = "MIT"
name = "multiaddr"
readme = "README.md"
version = "0.11.2"

[features]
Expand Down
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# rust-multiaddr

[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
[![](https://img.shields.io/badge/project-multiformats-blue.svg?style=flat-square)](https://github.com/multiformats/multiformats)
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](https://webchat.freenode.net/?channels=%23ipfs)
[![Travis CI](https://img.shields.io/travis/multiformats/rust-multiaddr.svg?style=flat-square&branch=master)](https://travis-ci.org/multiformats/rust-multiaddr)
[![codecov.io](https://img.shields.io/codecov/c/github/multiformats/rust-multiaddr.svg?style=flat-square&branch=master)](https://codecov.io/github/multiformats/rust-multiaddr?branch=master)
[![](https://img.shields.io/badge/rust-docs-blue.svg?style=flat-square)](https://docs.rs/crate/multiaddr)
[![crates.io](https://img.shields.io/badge/crates.io-v0.2.0-orange.svg?style=flat-square )](https://crates.io/crates/multiaddr)
[![](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)


> [multiaddr](https://github.com/multiformats/multiaddr) implementation in Rust.
## Table of Contents

- [Install](#install)
- [Usage](#usage)
- [Maintainers](#maintainers)
- [Contribute](#contribute)
- [License](#license)

## Install

First add this to your `Cargo.toml`

```toml
[dependencies]
multiaddr = "*"
```

then run `cargo build`.

## Usage

```rust
extern crate multiaddr;

use multiaddr::{Multiaddr, ToMultiaddr};

let address = "/ip4/127.0.0.1/udp/1234".parse::<Multiaddr>().unwrap();
// or directly from a string
let other = "/ip4/127.0.0.1".to_multiaddr().unwrap();

assert_eq!(address.to_string(), "/ip4/127.0.0.1/udp/1234");
assert_eq!(other.to_string(), "/ip4/127.0.0.1");
```

## Maintainers

Captain: [@dignifiedquire](https://github.com/dignifiedquire).

## Contribute

Contributions welcome. Please check out [the issues](https://github.com/multiformats/rust-multiaddr/issues).

Check out our [contributing document](https://github.com/multiformats/multiformats/blob/master/contributing.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to multiformats are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).

Small note: If editing the README, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.

## License

[MIT](LICENSE) © 2015-2017 Friedel Ziegelmeyer
2 changes: 1 addition & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl fmt::Display for Error {

impl error::Error for Error {
#[inline]
fn cause(&self) -> Option<&dyn error::Error> {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
if let Error::ParsingError(e) = self {
Some(&**e)
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/from_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::{error, fmt, iter, net::IpAddr};
/// # Example
///
/// ```
/// let addr = parity_multiaddr::from_url("ws://127.0.0.1:8080/").unwrap();
/// let addr = multiaddr::from_url("ws://127.0.0.1:8080/").unwrap();
/// assert_eq!(addr, "/ip4/127.0.0.1/tcp/8080/ws".parse().unwrap());
/// ```
///
Expand All @@ -41,8 +41,8 @@ pub fn from_url(url: &str) -> std::result::Result<Multiaddr, FromUrlErr> {
///
/// ```
/// let addr = "ws://user:[email protected]:8080/";
/// assert!(parity_multiaddr::from_url(addr).is_err());
/// assert!(parity_multiaddr::from_url_lossy(addr).is_ok());
/// assert!(multiaddr::from_url(addr).is_err());
/// assert!(multiaddr::from_url_lossy(addr).is_ok());
/// ```
///
pub fn from_url_lossy(url: &str) -> std::result::Result<Multiaddr, FromUrlErr> {
Expand Down
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl Multiaddr {
/// # Examples
///
/// ```
/// use parity_multiaddr::{Multiaddr, Protocol};
/// use multiaddr::{Multiaddr, Protocol};
///
/// let mut address: Multiaddr = "/ip4/127.0.0.1".parse().unwrap();
/// address.push(Protocol::Tcp(10000));
Expand All @@ -90,7 +90,7 @@ impl Multiaddr {

/// Pops the last `Protocol` of this multiaddr, or `None` if the multiaddr is empty.
/// ```
/// use parity_multiaddr::{Multiaddr, Protocol};
/// use multiaddr::{Multiaddr, Protocol};
///
/// let mut address: Multiaddr = "/ip4/127.0.0.1/udt/sctp/5678".parse().unwrap();
///
Expand Down Expand Up @@ -129,7 +129,7 @@ impl Multiaddr {
///
/// ```rust
/// use std::net::Ipv4Addr;
/// use parity_multiaddr::{Multiaddr, Protocol};
/// use multiaddr::{Multiaddr, Protocol};
///
/// let address: Multiaddr = "/ip4/127.0.0.1/udt/sctp/5678".parse().unwrap();
///
Expand Down Expand Up @@ -198,7 +198,7 @@ impl fmt::Display for Multiaddr {
/// # Example
///
/// ```
/// use parity_multiaddr::Multiaddr;
/// use multiaddr::Multiaddr;
///
/// let address: Multiaddr = "/ip4/127.0.0.1/udt".parse().unwrap();
/// assert_eq!(address.to_string(), "/ip4/127.0.0.1/udt");
Expand Down Expand Up @@ -408,7 +408,7 @@ impl<'de> Deserialize<'de> for Multiaddr {
/// Example:
///
/// ```rust
/// # use parity_multiaddr::multiaddr;
/// # use multiaddr::multiaddr;
/// let addr = multiaddr!(Ip4([127, 0, 0, 1]), Tcp(10500u16));
/// ```
///
Expand Down
1 change: 0 additions & 1 deletion src/protocol.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use arrayref::array_ref;
use byteorder::{BigEndian, ByteOrder, ReadBytesExt, WriteBytesExt};
use crate::{Result, Error};
Expand Down
6 changes: 2 additions & 4 deletions tests/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

use data_encoding::HEXUPPER;
use multihash::Multihash;
use parity_multiaddr::*;
use multiaddr::*;
use quickcheck::{Arbitrary, Gen, QuickCheck};
use rand::Rng;
use std::{
Expand Down Expand Up @@ -286,11 +285,10 @@ fn construct_fail() {
];

for address in &addresses {
assert!(address.parse::<Multiaddr>().is_err(), address.to_string());
assert!(address.parse::<Multiaddr>().is_err(), "{}", address.to_string());
}
}


#[test]
fn to_multiaddr() {
assert_eq!(Multiaddr::from(Ipv4Addr::new(127, 0, 0, 1)), "/ip4/127.0.0.1".parse().unwrap());
Expand Down

0 comments on commit 935a966

Please sign in to comment.