leptos-rs/leptos · info
should serialize string
Error message
should serialize string
What it means
This is a test assertion inside the oco crate: serde_json::to_string(&Oco::Borrowed("foo")) is expected to succeed, since Oco<'a, str> serializes as a plain string. The expect fires only if serialization returns an Err, which would indicate a broken Serialize impl for the Oco type rather than a user-facing condition.
Source
Thrown at oco/src/lib.rs:733
#[test]
fn cloned_inplace_borrowed_str_should_make_borrowed_str_and_remain_borrowed(
) {
let mut s: Oco<str> = Oco::Borrowed("hello");
assert!(s.clone_inplace().is_borrowed());
assert!(s.is_borrowed());
}
#[test]
fn cloned_inplace_counted_str_should_make_counted_str_and_remain_counted() {
let mut s: Oco<str> = Oco::Counted(Arc::from("hello"));
assert!(s.clone_inplace().is_counted());
assert!(s.is_counted());
}
#[test]
fn serialization_works() {
let s = serde_json::to_string(&Oco::Borrowed("foo"))
.expect("should serialize string");
assert_eq!(s, "\"foo\"");
}
#[test]
fn deserialization_works() {
let s: Oco<str> = serde_json::from_str("\"bar\"")
.expect("should deserialize from string");
assert_eq!(s, Oco::from(String::from("bar")));
}
}
View on GitHub (pinned to 32d20f6c9d)
Solutions
- Re-enable the `serde` feature of the oco crate so Serialize/Deserialize impls are compiled.
- Fix or restore the Serialize impl for Oco so all variants (Borrowed, Counted, Owned) emit plain strings.
- Check for serde/serde_json version incompatibilities introduced by Cargo.lock updates.
- Run cargo test -p oco to confirm the fix.
Example fix
// before: feature missing in Cargo.toml
oco = { path = "../oco", default-features = false }
// after
oco = { path = "../oco", features = ["serde"] } Defensive patterns
Strategy: type-guard
Type guard
fn is_oco_str_serializable(v: &Oco<'_, str>) -> bool {
serde_json::to_string(v).is_ok()
} Try / catch
match serde_json::to_string(&value) {
Ok(s) => s,
Err(e) => { log::error!("oco serialization failed: {e}"); String::new() }
} Prevention
- Keep the `serde` feature enabled for the oco crate.
- Run cargo test -p oco after version bumps.
- Keep all Oco variants covered by the Serialize impl.
When it happens
Trigger: Only in the crate's own test suite (serialization_works): a regression in Oco's Serialize implementation, an incompatible serde_json version, or a feature-flag combination (e.g. serde feature off) that breaks serialization.
Common situations: Contributors bumping serde/serde_json versions, disabling default features, or modifying Oco's enum variants so the Serialize derive/impl no longer handles Borrowed correctly.
Related errors
- should deserialize from string
- Unsupported server function HTTP method: {method:?}
- {}
- Reading from a LocalResource outside Suspense in `ssr` mode
- at {location}, the `sandboxed-arenas` feature is active, but
AI-assisted analysis of leptos-rs/leptos@32d20f6c9d (2026-09-01).
Data as JSON: /api/errors/8b775cfe59d2e6dd.
Report an issue: GitHub.