-
Notifications
You must be signed in to change notification settings - Fork 533
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add From instances for Value (#1091)
* Add Into instances for Value * Update conversions.rs * rustfmt
- Loading branch information
1 parent
a291d06
commit 23d9fd7
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use crate::protobuf::Value; | ||
use crate::value; | ||
use crate::String; | ||
use crate::Vec; | ||
use ::prost::alloc::collections::BTreeMap; | ||
|
||
impl From<value::Kind> for Value { | ||
fn from(value: value::Kind) -> Self { | ||
Value { kind: Some(value) } | ||
} | ||
} | ||
|
||
macro_rules! impl_number_value { | ||
($t: ty) => { | ||
impl From<$t> for Value { | ||
fn from(value: $t) -> Self { | ||
value::Kind::NumberValue(value.into()).into() | ||
} | ||
} | ||
}; | ||
} | ||
|
||
impl_number_value!(u8); | ||
impl_number_value!(u16); | ||
impl_number_value!(u32); | ||
|
||
impl_number_value!(i8); | ||
impl_number_value!(i16); | ||
impl_number_value!(i32); | ||
|
||
impl_number_value!(f32); | ||
impl_number_value!(f64); | ||
|
||
impl From<bool> for Value { | ||
fn from(value: bool) -> Self { | ||
value::Kind::BoolValue(value).into() | ||
} | ||
} | ||
|
||
impl From<String> for Value { | ||
fn from(value: String) -> Self { | ||
value::Kind::StringValue(value).into() | ||
} | ||
} | ||
|
||
impl<'a> From<&'a str> for Value { | ||
fn from(value: &str) -> Self { | ||
value::Kind::StringValue(value.into()).into() | ||
} | ||
} | ||
|
||
impl From<Vec<Value>> for Value { | ||
fn from(value: Vec<Value>) -> Self { | ||
value::Kind::ListValue(crate::protobuf::ListValue { values: value }).into() | ||
} | ||
} | ||
|
||
impl From<BTreeMap<String, Value>> for Value { | ||
fn from(value: BTreeMap<String, Value>) -> Self { | ||
value::Kind::StructValue(crate::protobuf::Struct { fields: value }).into() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters