dtolnay / typetag

Serde serializable and deserializable trait objects
Apache License 2.0
1.19k stars 38 forks source link

Could the tag optionally come from a constant instead of a string literal? #74

Open rukai opened 8 months ago

rukai commented 8 months ago

I can see that the name string literal is used in a function call here: https://github.com/dtolnay/typetag/blob/bb67b9e5feb6007e37b9760a30afacfb5900eeb0/impl/src/tagged_impl.rs#L37 So I think typetag could additionally support the user specifying the name as a constant by specifying the constant instead of a string literal:

const CONSTANT: &str = "some name";
#[typetag::serde(name = CONSTANT)]
impl Foo for Bar { }

This would allow the user to reuse the tag name in other locations.

Does that sound reasonable to you?

dtolnay commented 8 months ago

Yes, I would accept a PR for this.