What Is New in Rust 1.94
| Category | Highlights |
|---|---|
| New Features | array_windows iterator, Cargo config include key, TOML 1.1 parsing, const-stable APIs |
| Improvements | Better ergonomics for slice windows, richer Cargo configuration management, modern TOML syntax support |
How does the new array_windows method simplify sliding-window logic?
The array_windows method returns an iterator of fixed-size array references, letting you work with compile-time sized windows without manual indexing.
In practice you can replace a .windows(4) call with a more ergonomic pattern match on the array itself:
fn has_abba(s: &str) -> bool {
s.as_bytes()
.array_windows()
.any(|[a1, b1, b2, a2]| (a1 != b1) && (a1 == a2) && (b1 == b2))
}
- Zero-cost bounds checks: the compiler can prove the slice is long enough.
- Destructuring directly yields the individual elements, reducing boilerplate.
- Works for any
Nknown at compile time, making generic algorithms cleaner.
What is the Cargo include key and how can it be used?
The include key lets a Cargo configuration file pull in additional TOML files, promoting modular and shareable config sets.
Typical usage in .cargo/config.toml:
# array of paths
include = [
"frodo.toml",
"samwise.toml",
]
# inline tables for more control
include = [
{ path = "required.toml" },
{ path = "optional.toml", optional = true },
]
- Separate concerns (e.g., CI settings vs. local overrides) without duplication.
- The
optional = trueflag prevents errors when a file is missing, useful for per-developer tweaks. - All included files are merged before Cargo evaluates the final configuration.
How does Cargo's TOML 1.1 support affect my Cargo.toml files?
Cargo now parses TOML 1.1, allowing newer syntax such as multi-line inline tables, trailing commas, and additional escape sequences.
Example of the new style:
serde = {
version = "1.0",
features = ["derive"],
}
Impact considerations:
- Using TOML 1.1 raises your crate's MSRV to the first Rust version that bundles the updated Cargo parser.
- Third-party tools that read manifests may need updates, but Cargo automatically rewrites published manifests for older parsers.
- Existing projects can adopt the new syntax incrementally; older syntax continues to work.
Which APIs are now const-stable in Rust 1.94?
Several previously stable APIs have been promoted to const-stable, meaning they can be used inside const contexts.
Typical scenarios include compile-time calculations in embedded firmware or const-evaluated data structures. Example APIs (exact list in the release notes) can now appear in const fn bodies without requiring nightly.
- Enables more expressive
constinitializers, reducing runtime overhead. - Improves ergonomics for generic const code, especially in no-std environments.
- No breaking changes; existing const code continues to compile.
FAQ
Do I need to update my toolchain to use the new Cargo features?
You only need to run rustup update stable to get the latest Cargo version.
Can I use array_windows on the nightly channel before it stabilizes?
Yes, the method is already available on nightly and works identically.
Will enabling TOML 1.1 break compatibility with older Cargo versions?
Cargo rewrites manifests on publish, so older Cargo can still read the crate.
How do I mark an included Cargo config file as optional?
Use the inline table syntax with optional = true, for example { path = "dev.toml", optional = true }.
Which const-stable APIs are most useful for embedded development?
APIs that perform arithmetic or slice manipulation in const contexts are now usable, allowing zero-cost initialization.
Is there a code example that shows the new TOML syntax?
You can write serde = { version = "1.0", features = ["derive"], } in Cargo.toml.