1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
// The `Type` enumeration is the single-source of truth for type strings in Tonic.
#[derive(Debug, PartialEq)]
pub enum Type {
String,
Bool,
Number,
}
impl Type {
/// Check whether a string is a valid type string.
pub fn valid(string: impl Into<String>) -> bool {
match string.into().as_str() {
"string" | "bool" | "number" => true,
_ => false,
}
}
/// Convert a type string into a valid `Type` variant.
pub fn string(string: String) -> Self {
match string.as_str() {
"string" => Type::String,
"bool" => Type::Bool,
"number" => Type::Number,
_ => todo!()
}
}
}