Skip to content

Switchyard lets LLM applications route traffic across models and providers while preserving native OpenAI and Anthropic API compatibility - enabling flexible model selection, benchmarking, and cost/performance optimization.

Rust

feat: Upgrade to Rust 1.99 (#896)

Graham King12922d572d93
diff --git a/Cargo.lock b/Cargo.lock
index b1cbce1be..aeeeaf37b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -130,13 +130,13 @@ dependencies = [
[[package]]
name = "async-trait"
-version = "0.1.89"
+version = "0.1.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb"
+checksum = "82f6aeea286b8eb4dd3431a1be1b59d290ace00f5bfd8e2a159bc2a05e2c1667"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.119",
+ "syn 3.0.3",
]
[[package]]
@@ -512,7 +512,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
dependencies = [
"libc",
- "windows-sys 0.52.0",
+ "windows-sys 0.61.2",
]
[[package]]
@@ -1764,7 +1764,7 @@ dependencies = [
"once_cell",
"socket2",
"tracing",
- "windows-sys 0.52.0",
+ "windows-sys 0.61.2",
]
[[package]]
@@ -1998,7 +1998,7 @@ dependencies = [
"errno",
"libc",
"linux-raw-sys",
- "windows-sys 0.52.0",
+ "windows-sys 0.61.2",
]
[[package]]
@@ -2055,7 +2055,7 @@ dependencies = [
"security-framework",
"security-framework-sys",
"webpki-root-certs",
- "windows-sys 0.52.0",
+ "windows-sys 0.61.2",
]
[[package]]
@@ -2478,7 +2478,6 @@ dependencies = [
name = "switchyard-skill-distillation"
version = "0.3.0"
dependencies = [
- "async-trait",
"serde",
"serde_json",
"thiserror 2.0.18",
@@ -2575,7 +2574,7 @@ dependencies = [
"getrandom 0.4.3",
"once_cell",
"rustix",
- "windows-sys 0.52.0",
+ "windows-sys 0.61.2",
]
[[package]]
@@ -3123,7 +3122,7 @@ version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
dependencies = [
- "windows-sys 0.52.0",
+ "windows-sys 0.61.2",
]
[[package]]
diff --git a/Cargo.toml b/Cargo.toml
index 4151bc415..a3c8c9d02 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -23,11 +23,12 @@ authors = ["NVIDIA Corporation"]
edition = "2024"
license = "Apache-2.0"
repository = "https://github.com/NVIDIA-NeMo/Switchyard"
+# Minimum support Rust version. Always older than rust-toolchain.toml.
rust-version = "1.96.1"
[workspace.dependencies]
async-stream = "0.3"
-async-trait = "0.1"
+async-trait = "0.1.92"
base64 = "0.22"
futures = "0.3"
futures-util = "0.3"
diff --git a/crates/prefill-router/src/transformers.rs b/crates/prefill-router/src/transformers.rs
index 32ae60f32..749599791 100644
--- a/crates/prefill-router/src/transformers.rs
+++ b/crates/prefill-router/src/transformers.rs
@@ -176,9 +176,11 @@ fn decode_probabilities(
)));
}
let values = bytes
- .chunks_exact(size_of::<f32>())
+ .as_chunks::<{ size_of::<f32>() }>()
+ .0
+ .iter()
.map(|bytes| {
- let value = f32::from_ne_bytes([bytes[0], bytes[1], bytes[2], bytes[3]]);
+ let value = f32::from_ne_bytes(*bytes);
if value.is_finite() && (0.0..=1.0).contains(&value) {
Ok(value)
} else {
@@ -210,8 +212,10 @@ fn decode_expected_probabilities(
));
}
Ok(bytes
- .chunks_exact(size_of::<f32>())
- .map(|bytes| f32::from_ne_bytes([bytes[0], bytes[1], bytes[2], bytes[3]]))
+ .as_chunks::<{ size_of::<f32>() }>()
+ .0
+ .iter()
+ .map(|bytes| f32::from_ne_bytes(*bytes))
.collect::<Vec<_>>()
.chunks_exact(output_count)
.map(<[f32]>::to_vec)
diff --git a/crates/switchyard-skill-distillation/Cargo.toml b/crates/switchyard-skill-distillation/Cargo.toml
index 11093f444..f640ba8b8 100644
--- a/crates/switchyard-skill-distillation/Cargo.toml
+++ b/crates/switchyard-skill-distillation/Cargo.toml
@@ -12,7 +12,6 @@ repository.workspace = true
rust-version.workspace = true
[dependencies]
-async-trait.workspace = true
serde.workspace = true
serde_json.workspace = true
thiserror.workspace = true
diff --git a/crates/switchyard-skill-distillation/src/ports.rs b/crates/switchyard-skill-distillation/src/ports.rs
index 0203157bd..45dc1cbf4 100644
--- a/crates/switchyard-skill-distillation/src/ports.rs
+++ b/crates/switchyard-skill-distillation/src/ports.rs
@@ -6,7 +6,7 @@
//! These traits describe separate workflow steps. They do not call one another or
//! decide when distillation runs or when a candidate becomes the active skill.
-use async_trait::async_trait;
+use std::future::Future;
use crate::error::Result;
use crate::ids::{SkillNamespace, SkillVersionId};
@@ -15,46 +15,55 @@ use crate::model::{
};
/// Loads normalized trajectories for a target namespace.
-#[async_trait]
pub trait TrajectorySource: Send + Sync {
/// Loads all trajectories currently available for `namespace`.
- async fn load(&self, namespace: &SkillNamespace) -> Result<Vec<Trajectory>>;
+ fn load(
+ &self,
+ namespace: &SkillNamespace,
+ ) -> impl Future<Output = Result<Vec<Trajectory>>> + Send;
}
/// Converts normalized trajectories into a candidate skill.
-#[async_trait]
pub trait SkillDistiller: Send + Sync {
/// Produces a candidate without implicitly activating it.
- async fn distill(&self, request: &DistillationRequest) -> Result<SkillCandidate>;
+ fn distill(
+ &self,
+ request: &DistillationRequest,
+ ) -> impl Future<Output = Result<SkillCandidate>> + Send;
}
/// Evaluates a candidate against optional evaluation trajectories.
-#[async_trait]
pub trait SkillValidator: Send + Sync {
/// Returns validation evidence; activation remains a caller decision.
- async fn validate(
+ fn validate(
&self,
candidate: &SkillCandidate,
evaluation: &[Trajectory],
- ) -> Result<ValidationReport>;
+ ) -> impl Future<Output = Result<ValidationReport>> + Send;
}
/// Persists candidates and controls the active skill version.
-#[async_trait]
pub trait SkillStore: Send + Sync {
/// Returns the active candidate for `namespace`, when one exists.
- async fn active(&self, namespace: &SkillNamespace) -> Result<Option<SkillCandidate>>;
+ fn active(
+ &self,
+ namespace: &SkillNamespace,
+ ) -> impl Future<Output = Result<Option<SkillCandidate>>> + Send;
/// Persists a candidate without activating it.
- async fn save_candidate(&self, candidate: &SkillCandidate) -> Result<()>;
+ fn save_candidate(&self, candidate: &SkillCandidate)
+ -> impl Future<Output = Result<()>> + Send;
/// Activates a previously saved version.
- async fn activate(
+ fn activate(
&self,
namespace: &SkillNamespace,
version: &SkillVersionId,
- ) -> Result<ActivationRecord>;
+ ) -> impl Future<Output = Result<ActivationRecord>> + Send;
/// Restores the immediately preceding active version.
- async fn rollback(&self, namespace: &SkillNamespace) -> Result<ActivationRecord>;
+ fn rollback(
+ &self,
+ namespace: &SkillNamespace,
+ ) -> impl Future<Output = Result<ActivationRecord>> + Send;
}
diff --git a/crates/switchyard-skill-distillation/tests/contracts.rs b/crates/switchyard-skill-distillation/tests/contracts.rs
index 488c595a1..9e679b1be 100644
--- a/crates/switchyard-skill-distillation/tests/contracts.rs
+++ b/crates/switchyard-skill-distillation/tests/contracts.rs
@@ -6,7 +6,6 @@
use std::collections::BTreeMap;
use std::sync::Arc;
-use async_trait::async_trait;
use serde_json::json;
use switchyard_skill_distillation::{
ActivationOperation, ActivationRecord, DistillationRequest, ExecutionMetadata, Metadata,
@@ -130,7 +129,6 @@ struct StaticSource {
values: Vec<Trajectory>,
}
-#[async_trait]
impl TrajectorySource for StaticSource {
async fn load(&self, _namespace: &SkillNamespace) -> Result<Vec<Trajectory>> {
Ok(self.values.clone())
@@ -139,7 +137,6 @@ impl TrajectorySource for StaticSource {
struct StubDistiller;
-#[async_trait]
impl SkillDistiller for StubDistiller {
async fn distill(&self, request: &DistillationRequest) -> Result<SkillCandidate> {
request.validate()?;
@@ -149,7 +146,6 @@ impl SkillDistiller for StubDistiller {
struct StubValidator;
-#[async_trait]
impl SkillValidator for StubValidator {
async fn validate(
&self,
@@ -184,7 +180,6 @@ struct MemoryStore {
state: Arc<Mutex<StoreState>>,
}
-#[async_trait]
impl SkillStore for MemoryStore {
async fn active(&self, namespace: &SkillNamespace) -> Result<Option<SkillCandidate>> {
Ok(self.state.lock().await.active.get(namespace).cloned())
diff --git a/rust-toolchain.toml b/rust-toolchain.toml
index b49ef4fd4..89b6c538c 100644
--- a/rust-toolchain.toml
+++ b/rust-toolchain.toml
@@ -1,4 +1,4 @@
[toolchain]
-channel = "1.96.1"
+channel = "1.99"
components = ["clippy", "rustfmt", "rust-analyzer"]
profile = "minimal"