Registry / serialization / typetag

typetag

JSON →
library0.2.21rscratesunverified

Serde serializable and deserializable trait objects for Rust.

# Cargo.toml [dependencies] typetag = "0.2.21"
INSTALL
IMPORT
SIG · TYPETAG
T
typetag
serializationrustv0.2.21
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Serialize
use typetag::serde::Serialize;

Serializes a trait object to JSON using typetag.

use serde::{Serialize, Deserialize}; use typetag; #[typetag::serde] trait Animal: std::fmt::Debug {} #[derive(Debug, Serialize, Deserialize)] struct Dog { name: String } #[typetag::serde] impl Animal for Dog {} fn main() { let animal: Box<dyn Animal> = Box::new(Dog { name: "Rex".to_string() }); let json = serde_json::to_string(&animal).unwrap(); println!("JSON: {}", json); }
Debug
Known issues
gotchaRequires the 'serde' feature and careful handling of trait object registration.
fix
Enable the 'serde' feature and ensure all implementations are registered with #[typetag::serde].
affects: >=0.2.0
Upgrade
Version history
0.2.21latest on crates.io
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
typetag — cargo add typetag · libregistry