Skip to content

Commit cb280e5

Browse files
authored
Merge pull request #81 from newAM/ip_in_core
Add support for ip_in_core
2 parents 7732cb9 + 07c83ea commit cb280e5

File tree

11 files changed

+29
-8
lines changed

11 files changed

+29
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1010
* Add blanket impls of all the traits for mutable references.
1111
- Bump dependency version of `no-std-net` to `v0.6`.
1212
- Bump MSRV to 1.53.0 due to `no-std-net`'s use of or-patterns.
13+
- Added support for `core::net` with the `ip_in_core` feature.
1314

1415
## [0.6.0] - 2021-05-25
1516

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ readme = "README.md"
1717
keywords = ["network"]
1818
categories = ["embedded", "hardware-support", "no-std", "network-programming"]
1919

20+
[features]
21+
default = ["no-std-net"]
22+
ip_in_core = []
23+
2024
[dependencies]
2125
nb = "1"
22-
no-std-net = "0.6"
26+
no-std-net = { version = "0.6", optional = true }
2327
heapless = "^0.7"

embedded-nal-async/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ readme = "README.md"
1111
keywords = ["network"]
1212
categories = ["embedded", "hardware-support", "no-std", "network-programming", "asynchronous"]
1313

14+
[features]
15+
ip_in_core = []
16+
1417
[dependencies]
1518
no-std-net = "0.6"
1619
heapless = "^0.7"

embedded-nal-async/src/dns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use crate::IpAddr;
12
use embedded_nal::AddrType;
23
use heapless::String;
3-
use no_std_net::IpAddr;
44

55
/// This trait is an extension trait for [`TcpStack`] and [`UdpStack`] for dns
66
/// resolutions. It does not handle every DNS record type, but is meant as an

embedded-nal-async/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@
55
#![allow(incomplete_features)]
66
#![deny(missing_docs)]
77
#![deny(unsafe_code)]
8+
#![cfg_attr(feature = "ip_in_core", feature(ip_in_core))]
89

910
mod dns;
1011
mod stack;
1112
// Needed by embedded-nal trait implementers who build get_host_by_address results, or by trait
1213
// users who pass the results on.
1314
pub use heapless;
15+
16+
#[cfg(feature = "ip_in_core")]
17+
pub use core::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
18+
#[cfg(not(feature = "ip_in_core"))]
1419
pub use no_std_net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
1520

1621
pub use dns::Dns;

embedded-nal-async/src/stack/tcp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use no_std_net::SocketAddr;
1+
use crate::SocketAddr;
22

33
/// This trait is implemented by TCP/IP stacks. The trait allows the underlying driver to
44
/// construct multiple connections that implement the I/O traits from embedded-io.

embedded-nal-async/src/stack/udp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//! Implementing `UniquelyBound` and `MultiplyBound` with the same type is expected to be a
1515
//! common choice.
1616
17-
use no_std_net::SocketAddr;
17+
use crate::SocketAddr;
1818

1919
/// This trait is implemented by UDP sockets.
2020
///
@@ -140,7 +140,7 @@ pub trait UdpStack {
140140
&self,
141141
remote: SocketAddr,
142142
) -> Result<(SocketAddr, Self::Connected), Self::Error> {
143-
use no_std_net::{Ipv4Addr, Ipv6Addr, SocketAddr::*, SocketAddrV4, SocketAddrV6};
143+
use crate::{Ipv4Addr, Ipv6Addr, SocketAddr::*, SocketAddrV4, SocketAddrV6};
144144

145145
let local = match remote {
146146
V4(_) => V4(SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, 0)),

src/dns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
use crate::IpAddr;
12
use heapless::String;
2-
use no_std_net::IpAddr;
33

44
/// This is the host address type to be returned by `gethostbyname`.
55
///

src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#![no_std]
33
#![deny(missing_docs)]
44
#![deny(unsafe_code)]
5+
#![cfg_attr(feature = "ip_in_core", feature(ip_in_core))]
56

67
mod dns;
78
mod stack;
@@ -10,6 +11,13 @@ pub use nb;
1011
// Needed by embedded-nal trait implementers who build get_host_by_address results, or by trait
1112
// users who pass the results on.
1213
pub use heapless;
14+
15+
#[cfg(not(any(feature = "ip_in_core", feature = "no-std-net")))]
16+
compile_error!("You must select the ip_in_core feature or the no-std-net feature");
17+
18+
#[cfg(feature = "ip_in_core")]
19+
pub use core::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
20+
#[cfg(not(feature = "ip_in_core"))]
1321
pub use no_std_net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
1422

1523
pub use dns::{AddrType, Dns};

src/stack/tcp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use no_std_net::SocketAddr;
1+
use crate::SocketAddr;
22

33
/// This trait is implemented by TCP/IP stacks. You could, for example, have an implementation
44
/// which knows how to send AT commands to an ESP8266 WiFi module. You could have another implementation

0 commit comments

Comments
 (0)