Crates.io | prost-convert |
lib.rs | prost-convert |
version | 0.3.0 |
source | src |
created_at | 2024-08-19 09:40:35.168157 |
updated_at | 2024-08-19 09:40:35.168157 |
description | Generate more idiomatic rust code from GRPC proto files. |
homepage | |
repository | https://github.com/silicom-hub/prost-convert |
max_upload_size | |
id | 1343663 |
size | 24,172 |
From
and TryFrom
trait?We redefine our own conversion trait which might not seem logical.
The main reason is to support removing unwanted optional field
In rust we have
impl<T> From<T> for Option<T> { /**/}
which allows
let o: Option<u8> = Option::from(67);
assert_eq!(Some(67), o);
But if we have
struct U;
impl From<U> for T { /**/}
we don't have
impl<T, U> From<U> for Option<T>
where
T: From<U>,
{
fn from(value: U) -> Self {
Some(value.into())
}
}
We can't add this impl due to the orphan rule, so we add our own conversion trait. It’s mostly transparent to the user because most of the time it will be impl through a derive macro.
Bytes
https://docs.rs/prost/latest/prost/trait.Message.html#foreign-implsHashMap
to BTreeMap
so we should support BTreeMap
also.Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.