Implement various From and TryFrom for MetadataValue<Ascii>
- Dominant language
- Rust
- Stars
- 12.5k
- Forks
- 1.3k
- Avg merge
- 4d 7h
- Merged PRs (30d)
- 24
Description
## Feature Request
### Crates
- tonic
### Motivation
There's many places where the docs say "This function is intended to be replaced in the future by a TryFrom implementation once the trait is stabilized in std" e.g. [MetadataValue::from_str](https://docs.rs/tonic/latest/tonic/metadata/struct.MetadataValue.html#method.from_str). I assume these originally came from copying the Hyper `HeaderValue` methods, which have the same message, e.g. [HeaderValue::from_str](https://docs.rs/hyper/latest/hyper/header/struct.HeaderValue.html#method.from_str).
Integers can be infallibly encoded into ASCII, and so they can be infallibly used as metadata values. But right now there's no API for this -- you have to turn the integer into a string, then use the fallible `MetadataValue::from_str` method.
### Proposal
MetadataValue should impl the same From and TryFrom methods that hyper::HeaderValue does, i.e.
- From: i16, i32, i64, isize, u16, u32, u64, usize
- TryFrom: String, &String, &str
Then we should add a deprecation to the special "try_from" or "from" methods that currently exist, which these new From/TryFrom impls replace.
I'm happy to implement this if y'all like the idea.
### Alternatives
We could leave the current methods in place, but that's a bit less convenient for programmers.
Contributor guide
Assessment
This issue has not been assessed yet.