serde_context

Crates.ioserde_context
lib.rsserde_context
version0.1.0
created_at2025-12-30 14:30:58.348422+00
updated_at2025-12-30 14:30:58.348422+00
descriptionConvenient contextful (de)serialization compatible with the serde ecosystem
homepage
repositoryhttps://codeberg.org/blefebvre/serde_context
max_upload_size
id2012723
size43,163
Benjamin Lefebvre (lefebvreb)

documentation

https://docs.rs/serde_context

README

Serde Context

crates.io docs.rs

Convenient contextful (de)serialization compatible with the serde ecosystem.

You can find examples in the this crate's examples directory.

Limitations

There are a few limitations to this crate:

  • Only immutable references may be passed as context. You may still use interior mutability (Cells, RefCells, UnsafeCells...) to mutate state.
  • Only types implementing 'static can be used as context for (de)serialization. Unsized types are supported, though.
  • There is no type-checking of required context. Trying to (de)serialize a type that requires some context but failing to provide it will result in a runtime error.

Alternatives

There are a few alternatives to this crate you might want to consider, each with their pros and cons:

  • DeserializeSeed: the official serde stateful deserialization-only API. Requires implementing that trait for each type you are interested in deserializing, and no derive macro is provided (nor are there any plans to ever make an official one).
  • serde_state: a fork of serde that supports stateful (de)serialization. Unfortunately, it looks to be unmaintained.
  • serde_seeded: a crate providing an alternative version of the DeserializeSeed trait with a derive macro for it. Relatively young but very promising.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option. Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Commit count: 0

cargo fmt