Comment on Return Generic Type in Rust

Ogeon@programming.dev ⁨1⁩ ⁨year⁩ ago

It may be possible to use the Any trait to “launder” the value by first casting it to &Any and then downcasting it to the generic type.

let any_value = match tmp_value {
    serde_json::Value::Number(x) => x as &Any,
    // ...
};

let maybe_value = any_value.downcast_ref::();

I haven’t tested it, so I may have missed something.

source
Sort:hotnewtop