Skip to content

Commit edb6760

Browse files
authored
Merge pull request #9 from linksplatform/issue-8-53c25630aa7b
feat: migrate to stable Rust toolchain
2 parents 6ff3421 + 59016a2 commit edb6760

File tree

14 files changed

+229
-142
lines changed

14 files changed

+229
-142
lines changed

.github/workflows/release.yml

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ jobs:
4040
- uses: actions/checkout@v4
4141

4242
- name: Setup Rust
43-
uses: dtolnay/rust-toolchain@master
43+
uses: dtolnay/rust-toolchain@stable
4444
with:
45-
toolchain: nightly-2022-08-22
4645
components: rustfmt, clippy
4746

4847
- name: Cache cargo registry
@@ -60,7 +59,7 @@ jobs:
6059
run: cargo fmt --all -- --check
6160

6261
- name: Run Clippy
63-
run: cargo clippy --all-targets --all-features
62+
run: cargo clippy --all-targets --all-features -- -D warnings
6463

6564
- name: Check file size limit
6665
run: python3 scripts/check_file_size.py
@@ -77,9 +76,7 @@ jobs:
7776
- uses: actions/checkout@v4
7877

7978
- name: Setup Rust
80-
uses: dtolnay/rust-toolchain@master
81-
with:
82-
toolchain: nightly-2022-08-22
79+
uses: dtolnay/rust-toolchain@stable
8380

8481
- name: Cache cargo registry
8582
uses: actions/cache@v4
@@ -105,10 +102,8 @@ jobs:
105102
steps:
106103
- uses: actions/checkout@v4
107104

108-
- name: Setup Rust nightly
109-
uses: dtolnay/rust-toolchain@master
110-
with:
111-
toolchain: nightly-2022-08-22
105+
- name: Setup Rust
106+
uses: dtolnay/rust-toolchain@stable
112107

113108
# Install tarpaulin using pre-built binary (avoids compilation issues)
114109
- name: Install cargo-tarpaulin
@@ -154,9 +149,7 @@ jobs:
154149
- uses: actions/checkout@v4
155150

156151
- name: Setup Rust
157-
uses: dtolnay/rust-toolchain@master
158-
with:
159-
toolchain: nightly-2022-08-22
152+
uses: dtolnay/rust-toolchain@stable
160153

161154
- name: Cache cargo registry
162155
uses: actions/cache@v4
@@ -224,9 +217,7 @@ jobs:
224217
fetch-depth: 0
225218

226219
- name: Setup Rust
227-
uses: dtolnay/rust-toolchain@master
228-
with:
229-
toolchain: nightly-2022-08-22
220+
uses: dtolnay/rust-toolchain@stable
230221

231222
- name: Check if version changed
232223
id: version_check
@@ -272,9 +263,7 @@ jobs:
272263
token: ${{ secrets.GITHUB_TOKEN }}
273264

274265
- name: Setup Rust
275-
uses: dtolnay/rust-toolchain@master
276-
with:
277-
toolchain: nightly-2022-08-22
266+
uses: dtolnay/rust-toolchain@stable
278267

279268
- name: Configure git
280269
run: |

README.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,24 @@ use platform_data::Flow;
5353

5454
let mut collected = vec![];
5555

56+
// Use Flow with try_for_each by converting to ControlFlow
5657
(0..20).try_for_each(|i| {
5758
collected.push(i);
58-
if i == 10 { Flow::Break } else { Flow::Continue }
59+
if i == 10 { Flow::Break.into_control_flow() } else { Flow::Continue.into_control_flow() }
5960
});
6061

6162
assert_eq!(collected, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
63+
64+
// Or use Flow directly with manual iteration
65+
let mut collected2 = vec![];
66+
for i in 0..20 {
67+
collected2.push(i);
68+
let flow = if i == 10 { Flow::Break } else { Flow::Continue };
69+
if flow.is_break() {
70+
break;
71+
}
72+
}
73+
assert_eq!(collected2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
6274
```
6375

6476
### Using Point for repeated elements
@@ -144,17 +156,7 @@ use platform_data::{Links, LinkType, LinksConstants, Flow, Error, ReadHandler, W
144156

145157
## Requirements
146158

147-
This crate requires the **nightly** Rust toolchain due to the use of unstable features:
148-
149-
- `try_trait_v2`
150-
- `associated_type_bounds`
151-
- `type_alias_impl_trait`
152-
- `const_refs_to_cell`
153-
- `const_result_drop`
154-
- `const_trait_impl`
155-
- `const_convert`
156-
- `const_deref`
157-
- `step_trait`
159+
This crate requires **Rust 1.79 or later** (stable toolchain). The `associated_type_bounds` feature used for `Error:` bounds was stabilized in Rust 1.79.
158160

159161
## Dependencies
160162

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
### Changed
2+
- Migrated from nightly Rust to **stable Rust** toolchain (requires Rust 1.79+)
3+
- Removed all unstable feature flags:
4+
- `try_trait_v2` - Flow no longer implements `Try` trait
5+
- `type_alias_impl_trait` - Point now uses explicit `PointIter` type
6+
- `const_trait_impl`, `const_convert`, `const_deref`, `const_refs_to_cell`, `const_result_drop` - LinkType/FuntyPart traits are no longer const
7+
- `step_trait` - LinkType no longer requires `Step` bound
8+
- `associated_type_bounds` - still used but stabilized in Rust 1.79
9+
- `Flow` type changes:
10+
- Added `into_control_flow()` method for use with `try_for_each`
11+
- Removed `Try` and `FromResidual` trait implementations (nightly-only)
12+
- `Point` type changes:
13+
- Added explicit `PointIter` iterator type (publicly exported)
14+
- `LinkType` trait changes:
15+
- Removed `Step` trait bound
16+
- Removed `const` from trait and impl
17+
- `FuntyPart` trait changes:
18+
- Simplified implementation without const generics
19+
- Now uses `expect()` instead of `unreachable_unchecked()`
20+
- Updated CI/CD pipeline to use `dtolnay/rust-toolchain@stable`
21+
22+
### Fixed
23+
- Crate now compiles on stable Rust without any feature flags

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[toolchain]
2-
channel = "nightly-2022-08-22"
2+
channel = "stable"

rustfmt.toml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
error_on_line_overflow = true
2-
error_on_unformatted = true
3-
version = "Two"
4-
5-
imports_granularity = "Crate"
1+
# Stable rustfmt configuration
2+
# For available options, see: https://rust-lang.github.io/rustfmt/
3+
edition = "2018"

src/constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<T: LinkType> LinksConstants<T> {
9696
pub fn is_external(&self, address: T) -> bool {
9797
self.external_range
9898
.clone()
99-
.map_or(false, |range| range.contains(&address))
99+
.is_some_and(|range| range.contains(&address))
100100
}
101101

102102
pub fn is_reference(&self, address: T) -> bool {

src/converters.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
use crate::{Hybrid, LinkType};
2-
use funty::Integral;
3-
use std::ops::Sub;
42

53
#[derive(Default)]
64
pub struct AddrToRaw;

src/flow.rs

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,46 @@
1-
use std::ops::{ControlFlow, FromResidual, Try};
1+
use std::ops::ControlFlow;
22

3+
/// Represents the control flow of an operation, similar to `ControlFlow`.
4+
///
5+
/// This is a simplified enum that can be used with iterators and callbacks
6+
/// to indicate whether to continue or break early.
37
#[repr(usize)]
8+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
49
pub enum Flow {
510
Continue,
611
Break,
712
}
813

9-
impl FromResidual for Flow {
10-
fn from_residual(_: <Self as Try>::Residual) -> Self {
11-
Flow::Break
14+
impl Flow {
15+
/// Returns `true` if this is `Flow::Continue`.
16+
pub fn is_continue(&self) -> bool {
17+
matches!(self, Flow::Continue)
1218
}
13-
}
14-
15-
impl Try for Flow {
16-
type Output = ();
17-
type Residual = Flow;
1819

19-
fn from_output(_: Self::Output) -> Self {
20-
Flow::Continue
20+
/// Returns `true` if this is `Flow::Break`.
21+
pub fn is_break(&self) -> bool {
22+
matches!(self, Flow::Break)
2123
}
2224

23-
fn branch(self) -> ControlFlow<Self::Residual, Self::Output> {
25+
/// Converts this Flow into a ControlFlow that can be used with try_for_each.
26+
///
27+
/// This method enables using Flow with iterator methods like `try_for_each`:
28+
///
29+
/// ```
30+
/// use platform_data::Flow;
31+
/// use std::ops::ControlFlow;
32+
///
33+
/// let mut count = 0;
34+
/// let result = (0..10).try_for_each(|i| {
35+
/// count += 1;
36+
/// if i == 5 { Flow::Break.into_control_flow() } else { Flow::Continue.into_control_flow() }
37+
/// });
38+
/// assert_eq!(count, 6);
39+
/// ```
40+
pub fn into_control_flow(self) -> ControlFlow<()> {
2441
match self {
2542
Flow::Continue => ControlFlow::Continue(()),
26-
Flow::Break => ControlFlow::Break(Flow::Break),
43+
Flow::Break => ControlFlow::Break(()),
2744
}
2845
}
2946
}
@@ -36,3 +53,12 @@ impl<C, B> From<ControlFlow<C, B>> for Flow {
3653
}
3754
}
3855
}
56+
57+
impl From<Flow> for ControlFlow<()> {
58+
fn from(flow: Flow) -> Self {
59+
match flow {
60+
Flow::Continue => ControlFlow::Continue(()),
61+
Flow::Break => ControlFlow::Break(()),
62+
}
63+
}
64+
}

src/hybrid.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
use crate::LinkType;
2-
use funty::Integral;
3-
use std::ops::{Div, Sub};
42

53
#[derive(Debug, Clone, Copy, Hash, PartialOrd, PartialEq, Ord, Eq)]
64
pub struct Hybrid<T> {

src/lib.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
#![feature(try_trait_v2)]
2-
#![feature(associated_type_bounds)]
3-
#![feature(type_alias_impl_trait)]
4-
#![feature(const_refs_to_cell)]
5-
#![feature(const_result_drop)]
6-
#![feature(const_trait_impl)]
7-
#![feature(const_convert)]
8-
#![feature(const_deref)]
9-
#![feature(step_trait)]
10-
111
mod constants;
122
mod converters;
133
mod flow;
@@ -23,5 +13,5 @@ pub use flow::Flow;
2313
pub use hybrid::Hybrid;
2414
pub use link_type::LinkType;
2515
pub use links::{Error, Links, ReadHandler, WriteHandler};
26-
pub use point::Point;
16+
pub use point::{Point, PointIter};
2717
pub use query::{Query, ToQuery};

0 commit comments

Comments
 (0)