jamesmunns / postcard

A no_std + serde compatible message library for Rust
Apache License 2.0
930 stars 89 forks source link

schema: How to support niches like "byte array"? #147

Open jamesmunns opened 6 months ago

jamesmunns commented 6 months ago

As we provide blanket trait impls for &[T] and [T; N], I'm not sure if there is a way to EVER produce a bytearray variant in the Schema derive.

This is likely to be the case until some kind of stable specialization is possible.

dtolnay commented 6 months ago

I don't think specialization needs to come into play for this. You can do the same thing that std::hash::Hash does, where there is a default behavior that goes with [Self], and the trait impl for u8 overrided it with a different behavior.

jamesmunns commented 6 months ago

Thanks @dtolnay! I'll need to look into that. Right now the base impls of the Schema trait are in the repo, but I'll go look at std::hash::Hash, if you have any links handy I'm happy to take a look.

dtolnay commented 6 months ago

https://github.com/rust-lang/rust/blob/1.78.0/library/core/src/hash/mod.rs#L238

https://github.com/rust-lang/rust/blob/1.78.0/library/core/src/hash/mod.rs#L811

https://github.com/rust-lang/rust/blob/1.78.0/library/core/src/hash/mod.rs#L930