#![forbid(unsafe_code)]
use prost_types::{Enum, EnumValue, Field, Type};
pub trait TypeExt {
#[allow(clippy::new_ret_no_self)]
fn new(name: impl Into<String>) -> Type;
fn name(&self) -> &str;
fn fields(&self) -> &[Field];
fn oneofs(&self) -> &[String];
}
impl TypeExt for Type {
fn new(name: impl Into<String>) -> Type {
Type {
name: name.into(),
fields: Vec::new(),
oneofs: Vec::new(),
options: Vec::new(),
source_context: None,
syntax: 0,
}
}
fn name(&self) -> &str {
&self.name
}
fn fields(&self) -> &[Field] {
&self.fields
}
fn oneofs(&self) -> &[String] {
&self.oneofs
}
}
pub trait EnumTypeExt {
#[allow(clippy::new_ret_no_self)]
fn new(name: impl Into<String>) -> Enum;
fn name(&self) -> &str;
fn values(&self) -> &[EnumValue];
}
impl EnumTypeExt for Enum {
fn new(name: impl Into<String>) -> Enum {
Enum {
name: name.into(),
enumvalue: Vec::new(),
options: Vec::new(),
source_context: None,
syntax: 0,
}
}
fn name(&self) -> &str {
&self.name
}
fn values(&self) -> &[EnumValue] {
&self.enumvalue
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn type_new_and_name() {
let t = Type::new("google.protobuf.Timestamp");
assert_eq!(t.name(), "google.protobuf.Timestamp");
assert!(t.fields().is_empty());
assert!(t.oneofs().is_empty());
}
#[test]
fn enum_new_and_name() {
let e = Enum::new("google.protobuf.NullValue");
assert_eq!(e.name(), "google.protobuf.NullValue");
assert!(e.values().is_empty());
}
}