Skip to content

Commit 5740a0e

Browse files
committed
Add std feature that makes the library act as a facade to std::net
1 parent 51a4842 commit 5740a0e

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ cache: cargo
99
script:
1010
- cargo test --verbose
1111
- cargo build --features serde
12-
- cargo build --features std
12+
- cargo test --features std

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ serde = { version = "^1", default-features = false, optional = true }
2323
serde_test = "^1"
2424

2525
[features]
26+
# Makes the library act as a facade to std::net types
2627
std = []
2728
# Deprecated. Does nothing.
2829
i128 = []

src/lib.rs

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,32 +40,43 @@
4040
)]
4141
#![no_std]
4242
#![deny(
43-
dead_code,
44-
missing_docs,
45-
unused_imports,
46-
unused_must_use,
47-
unused_parens,
48-
unused_qualifications,
49-
warnings,
43+
dead_code,
44+
missing_docs,
45+
unused_imports,
46+
unused_must_use,
47+
unused_parens,
48+
unused_qualifications,
49+
warnings
5050
)]
5151
#![forbid(unsafe_code)]
5252

53-
#[cfg(feature = "std")]
54-
extern crate std;
55-
53+
#[cfg(not(feature = "std"))]
5654
use core::fmt;
5755

56+
#[cfg(not(feature = "std"))]
5857
mod addr;
58+
#[cfg(not(feature = "std"))]
5959
mod ip;
60+
#[cfg(not(feature = "std"))]
6061
mod parser;
6162

62-
#[cfg(feature = "serde")]
63+
#[cfg(all(not(feature = "std"), feature = "serde"))]
6364
extern crate serde;
64-
#[cfg(feature = "serde")]
65+
#[cfg(all(not(feature = "std"), feature = "serde"))]
6566
mod de;
66-
#[cfg(feature = "serde")]
67+
#[cfg(all(not(feature = "std"), feature = "serde"))]
6768
mod ser;
6869

70+
#[cfg(not(feature = "std"))]
71+
pub use addr::{SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs};
72+
#[cfg(not(feature = "std"))]
73+
pub use ip::{IpAddr, Ipv4Addr, Ipv6Addr, Ipv6MulticastScope};
6974

70-
pub use addr::{ SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs };
71-
pub use ip::{ IpAddr, Ipv4Addr, Ipv6Addr, Ipv6MulticastScope };
75+
// Re-export std::net types when std is available
76+
#[cfg(feature = "std")]
77+
extern crate std;
78+
// pub use std::net::Ipv6MulticastScope;
79+
#[cfg(feature = "std")]
80+
pub use std::net::{
81+
IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs,
82+
};

0 commit comments

Comments
 (0)