Skip to content

Commit 57b1dd4

Browse files
authored
Merge pull request #937 from umi-eng/core-net
Use `core` instead of `std` for net types.
2 parents a2a0dfb + 10d91bf commit 57b1dd4

File tree

15 files changed

+66
-72
lines changed

15 files changed

+66
-72
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "smoltcp"
33
version = "0.11.0"
44
edition = "2021"
5-
rust-version = "1.65"
5+
rust-version = "1.77"
66
authors = ["whitequark <[email protected]>"]
77
description = "A TCP/IP stack designed for bare-metal, real-time systems without a heap."
88
documentation = "https://docs.rs/smoltcp/"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ include complicated compile-time computations, such as macro or type tricks, eve
1212
at cost of performance degradation.
1313

1414
_smoltcp_ does not need heap allocation *at all*, is [extensively documented][docs],
15-
and compiles on stable Rust 1.65 and later.
15+
and compiles on stable Rust 1.77 and later.
1616

1717
_smoltcp_ achieves [~Gbps of throughput](#examplesbenchmarkrs) when tested against
1818
the Linux TCP stack in loopback mode.

ci.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -eox pipefail
44

55
export DEFMT_LOG=trace
66

7-
MSRV="1.65.0"
7+
MSRV="1.77.0"
88

99
RUSTC_VERSIONS=(
1010
$MSRV

src/iface/interface/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ impl Interface {
580580

581581
enum EgressError {
582582
Exhausted,
583-
Dispatch(DispatchError),
583+
Dispatch,
584584
}
585585

586586
let mut emitted_any = false;
@@ -602,7 +602,7 @@ impl Interface {
602602

603603
inner
604604
.dispatch_ip(t, meta, response, &mut self.fragmenter)
605-
.map_err(EgressError::Dispatch)?;
605+
.map_err(|_| EgressError::Dispatch)?;
606606

607607
emitted_any = true;
608608

@@ -673,7 +673,7 @@ impl Interface {
673673

674674
match result {
675675
Err(EgressError::Exhausted) => break, // Device buffer full.
676-
Err(EgressError::Dispatch(_)) => {
676+
Err(EgressError::Dispatch) => {
677677
// `NeighborCache` already takes care of rate limiting the neighbor discovery
678678
// requests from the socket. However, without an additional rate limiting
679679
// mechanism, we would spin on every socket that has yet to discover its

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
//!
6666
//! # Minimum Supported Rust Version (MSRV)
6767
//!
68-
//! This crate is guaranteed to compile on stable Rust 1.65 and up with any valid set of features.
68+
//! This crate is guaranteed to compile on stable Rust 1.77 and up with any valid set of features.
6969
//! It *might* compile on older versions but that may change in any new patch release.
7070
//!
7171
//! The exception is when using the `defmt` feature, in which case `defmt`'s MSRV applies, which

src/phy/loopback.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use alloc::collections::VecDeque;
2+
use alloc::vec;
23
use alloc::vec::Vec;
34

45
use crate::phy::{self, ChecksumCapabilities, Device, DeviceCapabilities, Medium};
@@ -80,8 +81,7 @@ impl<'a> phy::TxToken for TxToken<'a> {
8081
where
8182
F: FnOnce(&mut [u8]) -> R,
8283
{
83-
let mut buffer = Vec::new();
84-
buffer.resize(len, 0);
84+
let mut buffer = vec![0; len];
8585
let result = f(&mut buffer);
8686
self.queue.push_back(buffer);
8787
result

src/phy/sys/bpf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl BpfDevice {
172172
);
173173

174174
if len == -1 {
175-
Err(io::Error::last_os_error()).unwrap()
175+
panic!("{:?}", io::Error::last_os_error())
176176
}
177177

178178
Ok(len as usize)

src/wire/dns.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,9 @@ impl<'a> Repr<'a> {
417417
}
418418

419419
/// Emit a high-level representation into a DNS packet.
420-
pub fn emit<T: ?Sized>(&self, packet: &mut Packet<&mut T>)
420+
pub fn emit<T>(&self, packet: &mut Packet<&mut T>)
421421
where
422-
T: AsRef<[u8]> + AsMut<[u8]>,
422+
T: AsRef<[u8]> + AsMut<[u8]> + ?Sized,
423423
{
424424
packet.set_transaction_id(self.transaction_id);
425425
packet.set_flags(self.flags);
@@ -779,8 +779,7 @@ mod test {
779779
},
780780
};
781781

782-
let mut buf = Vec::new();
783-
buf.resize(repr.buffer_len(), 0);
782+
let mut buf = vec![0; repr.buffer_len()];
784783
repr.emit(&mut Packet::new_unchecked(&mut buf));
785784

786785
let want = &[

src/wire/ip.rs

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -195,38 +195,37 @@ impl Address {
195195
}
196196
}
197197

198-
#[cfg(all(feature = "std", feature = "proto-ipv4", feature = "proto-ipv6"))]
199-
impl From<::std::net::IpAddr> for Address {
200-
fn from(x: ::std::net::IpAddr) -> Address {
198+
#[cfg(all(feature = "proto-ipv4", feature = "proto-ipv6"))]
199+
impl From<::core::net::IpAddr> for Address {
200+
fn from(x: ::core::net::IpAddr) -> Address {
201201
match x {
202-
::std::net::IpAddr::V4(ipv4) => Address::Ipv4(ipv4.into()),
203-
::std::net::IpAddr::V6(ipv6) => Address::Ipv6(ipv6.into()),
202+
::core::net::IpAddr::V4(ipv4) => Address::Ipv4(ipv4.into()),
203+
::core::net::IpAddr::V6(ipv6) => Address::Ipv6(ipv6.into()),
204204
}
205205
}
206206
}
207207

208-
#[cfg(feature = "std")]
209-
impl From<Address> for ::std::net::IpAddr {
210-
fn from(x: Address) -> ::std::net::IpAddr {
208+
impl From<Address> for ::core::net::IpAddr {
209+
fn from(x: Address) -> ::core::net::IpAddr {
211210
match x {
212211
#[cfg(feature = "proto-ipv4")]
213-
Address::Ipv4(ipv4) => ::std::net::IpAddr::V4(ipv4.into()),
212+
Address::Ipv4(ipv4) => ::core::net::IpAddr::V4(ipv4.into()),
214213
#[cfg(feature = "proto-ipv6")]
215-
Address::Ipv6(ipv6) => ::std::net::IpAddr::V6(ipv6.into()),
214+
Address::Ipv6(ipv6) => ::core::net::IpAddr::V6(ipv6.into()),
216215
}
217216
}
218217
}
219218

220-
#[cfg(all(feature = "std", feature = "proto-ipv4"))]
221-
impl From<::std::net::Ipv4Addr> for Address {
222-
fn from(ipv4: ::std::net::Ipv4Addr) -> Address {
219+
#[cfg(feature = "proto-ipv4")]
220+
impl From<::core::net::Ipv4Addr> for Address {
221+
fn from(ipv4: ::core::net::Ipv4Addr) -> Address {
223222
Address::Ipv4(ipv4.into())
224223
}
225224
}
226225

227-
#[cfg(all(feature = "std", feature = "proto-ipv6"))]
228-
impl From<::std::net::Ipv6Addr> for Address {
229-
fn from(ipv6: ::std::net::Ipv6Addr) -> Address {
226+
#[cfg(feature = "proto-ipv6")]
227+
impl From<::core::net::Ipv6Addr> for Address {
228+
fn from(ipv6: ::core::net::Ipv6Addr) -> Address {
230229
Address::Ipv6(ipv6.into())
231230
}
232231
}
@@ -395,29 +394,29 @@ impl Endpoint {
395394
}
396395
}
397396

398-
#[cfg(all(feature = "std", feature = "proto-ipv4", feature = "proto-ipv6"))]
399-
impl From<::std::net::SocketAddr> for Endpoint {
400-
fn from(x: ::std::net::SocketAddr) -> Endpoint {
397+
#[cfg(all(feature = "proto-ipv4", feature = "proto-ipv6"))]
398+
impl From<::core::net::SocketAddr> for Endpoint {
399+
fn from(x: ::core::net::SocketAddr) -> Endpoint {
401400
Endpoint {
402401
addr: x.ip().into(),
403402
port: x.port(),
404403
}
405404
}
406405
}
407406

408-
#[cfg(all(feature = "std", feature = "proto-ipv4"))]
409-
impl From<::std::net::SocketAddrV4> for Endpoint {
410-
fn from(x: ::std::net::SocketAddrV4) -> Endpoint {
407+
#[cfg(feature = "proto-ipv4")]
408+
impl From<::core::net::SocketAddrV4> for Endpoint {
409+
fn from(x: ::core::net::SocketAddrV4) -> Endpoint {
411410
Endpoint {
412411
addr: (*x.ip()).into(),
413412
port: x.port(),
414413
}
415414
}
416415
}
417416

418-
#[cfg(all(feature = "std", feature = "proto-ipv6"))]
419-
impl From<::std::net::SocketAddrV6> for Endpoint {
420-
fn from(x: ::std::net::SocketAddrV6) -> Endpoint {
417+
#[cfg(feature = "proto-ipv6")]
418+
impl From<::core::net::SocketAddrV6> for Endpoint {
419+
fn from(x: ::core::net::SocketAddrV6) -> Endpoint {
421420
Endpoint {
422421
addr: (*x.ip()).into(),
423422
port: x.port(),
@@ -466,29 +465,29 @@ impl ListenEndpoint {
466465
}
467466
}
468467

469-
#[cfg(all(feature = "std", feature = "proto-ipv4", feature = "proto-ipv6"))]
470-
impl From<::std::net::SocketAddr> for ListenEndpoint {
471-
fn from(x: ::std::net::SocketAddr) -> ListenEndpoint {
468+
#[cfg(all(feature = "proto-ipv4", feature = "proto-ipv6"))]
469+
impl From<::core::net::SocketAddr> for ListenEndpoint {
470+
fn from(x: ::core::net::SocketAddr) -> ListenEndpoint {
472471
ListenEndpoint {
473472
addr: Some(x.ip().into()),
474473
port: x.port(),
475474
}
476475
}
477476
}
478477

479-
#[cfg(all(feature = "std", feature = "proto-ipv4"))]
480-
impl From<::std::net::SocketAddrV4> for ListenEndpoint {
481-
fn from(x: ::std::net::SocketAddrV4) -> ListenEndpoint {
478+
#[cfg(feature = "proto-ipv4")]
479+
impl From<::core::net::SocketAddrV4> for ListenEndpoint {
480+
fn from(x: ::core::net::SocketAddrV4) -> ListenEndpoint {
482481
ListenEndpoint {
483482
addr: Some((*x.ip()).into()),
484483
port: x.port(),
485484
}
486485
}
487486
}
488487

489-
#[cfg(all(feature = "std", feature = "proto-ipv6"))]
490-
impl From<::std::net::SocketAddrV6> for ListenEndpoint {
491-
fn from(x: ::std::net::SocketAddrV6) -> ListenEndpoint {
488+
#[cfg(feature = "proto-ipv6")]
489+
impl From<::core::net::SocketAddrV6> for ListenEndpoint {
490+
fn from(x: ::core::net::SocketAddrV6) -> ListenEndpoint {
492491
ListenEndpoint {
493492
addr: Some((*x.ip()).into()),
494493
port: x.port(),

src/wire/ipv4.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,14 @@ impl Address {
110110
}
111111
}
112112

113-
#[cfg(feature = "std")]
114-
impl From<::std::net::Ipv4Addr> for Address {
115-
fn from(x: ::std::net::Ipv4Addr) -> Address {
113+
impl From<::core::net::Ipv4Addr> for Address {
114+
fn from(x: ::core::net::Ipv4Addr) -> Address {
116115
Address(x.octets())
117116
}
118117
}
119118

120-
#[cfg(feature = "std")]
121-
impl From<Address> for ::std::net::Ipv4Addr {
122-
fn from(Address(x): Address) -> ::std::net::Ipv4Addr {
119+
impl From<Address> for ::core::net::Ipv4Addr {
120+
fn from(Address(x): Address) -> ::core::net::Ipv4Addr {
123121
x.into()
124122
}
125123
}

0 commit comments

Comments
 (0)