leptos-rs/leptos · info

should deserialize from string

Error message

should deserialize from string

What it means

Test assertion in the oco crate: deserializing the JSON string "\"bar\"" into Oco<'_, str> should succeed and yield Oco::from(String::from("bar")). The expect panics if serde_json::from_str returns Err, signaling a broken Deserialize impl for Oco rather than a runtime condition users can trigger.

Source

Thrown at oco/src/lib.rs:740

    #[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

  1. Enable the `serde` feature of the oco crate.
  2. Restore/fix the Deserialize impl (and its visitor) so string input deserializes into Oco::Owned/Counted.
  3. Pin compatible serde/serde_json versions and update Cargo.lock.
  4. Run cargo test -p oco to verify.
Defensive patterns

Strategy: type-guard

Type guard

fn parses_as_oco(raw: &str) -> bool {
    serde_json::from_str::<Oco<'_, str>>(raw).is_ok()
}

Try / catch

match serde_json::from_str::<Oco<str>>(raw) {
    Ok(v) => v,
    Err(e) => { log::error!("oco deserialization failed: {e}"); Oco::Borrowed("") }
}

Prevention

When it happens

Trigger: Only in the crate's own test suite (deserialization_works): a regression in Oco's Deserialize implementation, missing serde feature, or serde_json version incompatibility.

Common situations: Feature-flag changes that drop the Deserialize impl, editing Oco variants (e.g. lifetime changes) so the visitor no longer accepts strings, or Cargo.lock drift pulling a broken serde combination.

Related errors


AI-assisted analysis of leptos-rs/leptos@32d20f6c9d (2026-09-01). Data as JSON: /api/errors/1d0c70a26622e22f. Report an issue: GitHub.