Closed ufoscout closed 3 years ago
I wonder if it is possible to generate code with generics. For example, this simple code fails to run:
use serde::{Deserialize, Serialize}; use serde_reflection::{Tracer, TracerConfig}; #[derive(Serialize, Deserialize)] struct Test<T> { a: T, } #[derive(Serialize, Deserialize)] struct TestString { test: Test<String>, } #[derive(Serialize, Deserialize)] struct TestNumber { test: Test<usize>, } let mut tracer = Tracer::new(TracerConfig::default()); tracer.trace_simple_type::<TestString>().unwrap(); tracer.trace_simple_type::<TestNumber>().unwrap(); let registry = tracer.registry().unwrap();
The tracer.registry().unwrap() function call fails with this error:
tracer.registry().unwrap()
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Incompatible("Str", "U64")'
I can't figure out how to add the generic Test<T> struct to the tracer to let the code run as expected.
Test<T>
@ufoscout I'm happy to report that a work around is now available using new classes in the serde-name crate: https://docs.rs/serde-name/0.2.0/serde_name/
I wonder if it is possible to generate code with generics. For example, this simple code fails to run:
The
tracer.registry().unwrap()
function call fails with this error:I can't figure out how to add the generic
Test<T>
struct to the tracer to let the code run as expected.