Skip to content

Commit f403862

Browse files
bors[bot]Dirbaio
andauthored
Merge #572
572: GAT-based Device trait. r=Dirbaio a=Dirbaio The current `'a` lifetime in the `Device` trait is essentially a workaround for lack of GATs. I'm just experimenting how this would look like, it'll have to wait until GATs are stable to go in. The main benefit is structs implementing `Device` can now borrow stuff. This wasn't possible before because the `for<'d> T: Device<'d>` bounds would essentially imply `T: 'static`. Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
2 parents 202e9b4 + 13cc7f8 commit f403862

24 files changed

+119
-111
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ jobs:
2020
# Test on stable, MSRV, and nightly.
2121
# Failure is permitted on nightly.
2222
rust:
23-
- stable
24-
- 1.61.0
23+
#- stable # TODO: enable again when "stable" is 1.66 or higher.
24+
- 1.65.0
2525
- nightly
2626

2727
features:
@@ -64,8 +64,8 @@ jobs:
6464
# Test on stable, MSRV, and nightly.
6565
# Failure is permitted on nightly.
6666
rust:
67-
- stable
68-
- 1.61.0
67+
#- stable # TODO: enable again when "stable" is 1.66 or higher.
68+
- 1.65.0
6969
- nightly
7070

7171
features:

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- Remove IpAddress::Unspecified
1212
- When sending packets with a raw socket, the source IP address is sent unmodified (it was previously replaced with the interface's address if it was unspecified).
1313
- Fix enable `defmt/alloc` if `alloc` or `std` is enabled.
14-
- Minimum Supported Rust Version (MSRV) **bumped** from 1.56 to 1.60
14+
- Minimum Supported Rust Version (MSRV) **bumped** from 1.56 to 1.65
1515

1616
## [0.8.1] - 2022-05-12
1717

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.8.1"
44
edition = "2018"
5-
rust-version = "1.61"
5+
rust-version = "1.65"
66
authors = ["whitequark <whitequark@whitequark.org>"]
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
@@ -11,7 +11,7 @@ include complicated compile-time computations, such as macro or type tricks, eve
1111
at cost of performance degradation.
1212

1313
_smoltcp_ does not need heap allocation *at all*, is [extensively documented][docs],
14-
and compiles on stable Rust 1.61 and later.
14+
and compiles on stable Rust 1.65 and later.
1515

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

examples/utils.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,7 @@ pub fn parse_options(options: &Options, free: Vec<&str>) -> Matches {
8484
free.join(" ")
8585
);
8686
print!("{}", options.usage(&brief));
87-
process::exit(if matches.free.len() != free.len() {
88-
1
89-
} else {
90-
0
91-
})
87+
process::exit((matches.free.len() != free.len()) as _);
9288
}
9389
matches
9490
}
@@ -159,7 +155,7 @@ pub fn parse_middleware_options<D>(
159155
loopback: bool,
160156
) -> FaultInjector<Tracer<PcapWriter<D, Box<dyn io::Write>>>>
161157
where
162-
D: for<'a> Device<'a>,
158+
D: Device,
163159
{
164160
let drop_chance = matches
165161
.opt_str("drop-chance")

fuzz/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub fn parse_middleware_options<D>(
9393
loopback: bool,
9494
) -> FaultInjector<Tracer<PcapWriter<D, Box<dyn Write>>>>
9595
where
96-
D: for<'a> Device<'a>,
96+
D: Device,
9797
{
9898
let drop_chance = matches
9999
.opt_str("drop-chance")

src/iface/fragmentation.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ impl<'a, K: Eq + Ord + Clone + Copy> PacketAssemblerSet<'a, K> {
364364
/// - Returns [`Error::PacketAssemblerSetKeyNotFound`] when the key was not found in the set.
365365
pub(crate) fn get_packet_assembler_mut(&mut self, key: &K) -> Result<&mut PacketAssembler<'a>> {
366366
if let Some(i) = self.index_buffer.get(key) {
367-
Ok(&mut self.packet_buffer[*i as usize])
367+
Ok(&mut self.packet_buffer[*i])
368368
} else {
369369
Err(Error::PacketAssemblerSetKeyNotFound)
370370
}
@@ -379,7 +379,7 @@ impl<'a, K: Eq + Ord + Clone + Copy> PacketAssemblerSet<'a, K> {
379379
/// - Returns [`Error::PacketAssemblerIncomplete`] when the fragments assembler was empty or not fully assembled.
380380
pub(crate) fn get_assembled_packet(&mut self, key: &K) -> Result<&[u8]> {
381381
if let Some(i) = self.index_buffer.get(key) {
382-
let p = self.packet_buffer[*i as usize].assemble()?;
382+
let p = self.packet_buffer[*i].assemble()?;
383383
self.index_buffer.remove(key);
384384
Ok(p)
385385
} else {
@@ -392,10 +392,7 @@ impl<'a, K: Eq + Ord + Clone + Copy> PacketAssemblerSet<'a, K> {
392392
loop {
393393
let mut key = None;
394394
for (k, i) in self.index_buffer.iter() {
395-
if matches!(
396-
self.packet_buffer[*i as usize].assembler,
397-
AssemblerState::NotInit
398-
) {
395+
if matches!(self.packet_buffer[*i].assembler, AssemblerState::NotInit) {
399396
key = Some(*k);
400397
break;
401398
}
@@ -416,7 +413,7 @@ impl<'a, K: Eq + Ord + Clone + Copy> PacketAssemblerSet<'a, K> {
416413
F: Fn(&mut PacketAssembler<'_>) -> Result<bool>,
417414
{
418415
for (_, i) in &mut self.index_buffer.iter() {
419-
let frag = &mut self.packet_buffer[*i as usize];
416+
let frag = &mut self.packet_buffer[*i];
420417
if f(frag)? {
421418
frag.mark_discarded();
422419
}

src/iface/interface/ipv4.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ impl<'a> InterfaceInner<'a> {
507507
}
508508

509509
tx_buffer[repr.buffer_len()..][..payload_len].copy_from_slice(
510-
&buffer[*frag_offset as usize + repr.buffer_len() as usize..][..payload_len],
510+
&buffer[*frag_offset as usize + repr.buffer_len()..][..payload_len],
511511
);
512512

513513
// Update the frag offset for the next fragment.

src/iface/interface/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ let iface = builder.finalize(&mut device);
563563
/// [neighbor_cache]: #method.neighbor_cache
564564
pub fn finalize<D>(self, device: &mut D) -> Interface<'a>
565565
where
566-
D: for<'d> Device<'d> + ?Sized,
566+
D: Device + ?Sized,
567567
{
568568
let caps = device.capabilities();
569569

@@ -905,7 +905,7 @@ impl<'a> Interface<'a> {
905905
timestamp: Instant,
906906
) -> Result<bool>
907907
where
908-
D: for<'d> Device<'d> + ?Sized,
908+
D: Device + ?Sized,
909909
{
910910
self.inner.now = timestamp;
911911

@@ -947,7 +947,7 @@ impl<'a> Interface<'a> {
947947
timestamp: Instant,
948948
) -> Result<bool>
949949
where
950-
D: for<'d> Device<'d> + ?Sized,
950+
D: Device + ?Sized,
951951
{
952952
self.inner.now = timestamp;
953953

@@ -1047,7 +1047,7 @@ impl<'a> Interface<'a> {
10471047
sockets: &mut SocketSet<'_>,
10481048
) -> Result<bool>
10491049
where
1050-
D: for<'d> Device<'d> + ?Sized,
1050+
D: Device + ?Sized,
10511051
{
10521052
self.inner.now = timestamp;
10531053

@@ -1152,7 +1152,7 @@ impl<'a> Interface<'a> {
11521152

11531153
fn socket_ingress<D>(&mut self, device: &mut D, sockets: &mut SocketSet<'_>) -> bool
11541154
where
1155-
D: for<'d> Device<'d> + ?Sized,
1155+
D: Device + ?Sized,
11561156
{
11571157
let mut processed_any = false;
11581158
let Self {
@@ -1208,7 +1208,7 @@ impl<'a> Interface<'a> {
12081208

12091209
fn socket_egress<D>(&mut self, device: &mut D, sockets: &mut SocketSet<'_>) -> bool
12101210
where
1211-
D: for<'d> Device<'d> + ?Sized,
1211+
D: Device + ?Sized,
12121212
{
12131213
let Self {
12141214
inner,
@@ -1318,7 +1318,7 @@ impl<'a> Interface<'a> {
13181318
#[cfg(feature = "proto-igmp")]
13191319
fn igmp_egress<D>(&mut self, device: &mut D) -> Result<bool>
13201320
where
1321-
D: for<'d> Device<'d> + ?Sized,
1321+
D: Device + ?Sized,
13221322
{
13231323
match self.inner.igmp_report_state {
13241324
IgmpReportState::ToSpecificQuery {
@@ -1384,7 +1384,7 @@ impl<'a> Interface<'a> {
13841384
#[cfg(feature = "proto-ipv4-fragmentation")]
13851385
fn ipv4_egress<D>(&mut self, device: &mut D) -> Result<bool>
13861386
where
1387-
D: for<'d> Device<'d> + ?Sized,
1387+
D: Device + ?Sized,
13881388
{
13891389
// Reset the buffer when we transmitted everything.
13901390
if self.out_packets.ipv4_out_packet.finished() {
@@ -1422,7 +1422,7 @@ impl<'a> Interface<'a> {
14221422
#[cfg(feature = "proto-sixlowpan-fragmentation")]
14231423
fn sixlowpan_egress<D>(&mut self, device: &mut D) -> Result<bool>
14241424
where
1425-
D: for<'d> Device<'d> + ?Sized,
1425+
D: Device + ?Sized,
14261426
{
14271427
// Reset the buffer when we transmitted everything.
14281428
if self.out_packets.sixlowpan_out_packet.finished() {

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.61 and up with any valid set of features.
68+
//! This crate is guaranteed to compile on stable Rust 1.65 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

0 commit comments

Comments
 (0)