pub struct EnumRules {
pub const: Option<i32>,
pub defined_only: Option<bool>,
pub in: Vec<i32>,
pub not_in: Vec<i32>,
pub example: Vec<i32>,
}
Expand description
EnumRules describe the rules applied to enum
values.
Fields§
§const: Option<i32>
const
requires the field value to exactly match the specified enum value.
If the field value doesn’t match, an error message is generated.
enum MyEnum {
MY_ENUM_UNSPECIFIED = 0;
MY_ENUM_VALUE1 = 1;
MY_ENUM_VALUE2 = 2;
}
message MyMessage {
// The field `value` must be exactly MY_ENUM_VALUE1.
MyEnum value = 1 \[(buf.validate.field).enum.const = 1\];
}
defined_only: Option<bool>
defined_only
requires the field value to be one of the defined values for
this enum, failing on any undefined value.
enum MyEnum {
MY_ENUM_UNSPECIFIED = 0;
MY_ENUM_VALUE1 = 1;
MY_ENUM_VALUE2 = 2;
}
message MyMessage {
// The field `value` must be a defined value of MyEnum.
MyEnum value = 1 \[(buf.validate.field).enum.defined_only = true\];
}
in: Vec<i32>
in
requires the field value to be equal to one of the
specified enum values. If the field value doesn’t match any of the
specified values, an error message is generated.
enum MyEnum {
MY_ENUM_UNSPECIFIED = 0;
MY_ENUM_VALUE1 = 1;
MY_ENUM_VALUE2 = 2;
}
message MyMessage {
// The field `value` must be equal to one of the specified values.
MyEnum value = 1 \[(buf.validate.field).enum = { in: [1, 2\]}];
}
not_in: Vec<i32>
not_in
requires the field value to be not equal to any of the
specified enum values. If the field value matches one of the specified
values, an error message is generated.
enum MyEnum {
MY_ENUM_UNSPECIFIED = 0;
MY_ENUM_VALUE1 = 1;
MY_ENUM_VALUE2 = 2;
}
message MyMessage {
// The field `value` must not be equal to any of the specified values.
MyEnum value = 1 \[(buf.validate.field).enum = { not_in: [1, 2\]}];
}
example: Vec<i32>
example
specifies values that the field may have. These values SHOULD
conform to other rules. example
values will not impact validation
but may be used as helpful guidance on how to populate the given field.
enum MyEnum {
MY_ENUM_UNSPECIFIED = 0;
MY_ENUM_VALUE1 = 1;
MY_ENUM_VALUE2 = 2;
}
message MyMessage {
(buf.validate.field).enum.example = 1,
(buf.validate.field).enum.example = 2
}
Implementations§
Trait Implementations§
Source§impl Message for EnumRules
impl Message for EnumRules
Source§fn encoded_len(&self) -> usize
fn encoded_len(&self) -> usize
Source§fn encode(&self, buf: &mut impl BufMut) -> Result<(), EncodeError>where
Self: Sized,
fn encode(&self, buf: &mut impl BufMut) -> Result<(), EncodeError>where
Self: Sized,
Source§fn encode_to_vec(&self) -> Vec<u8> ⓘwhere
Self: Sized,
fn encode_to_vec(&self) -> Vec<u8> ⓘwhere
Self: Sized,
Source§fn encode_length_delimited(
&self,
buf: &mut impl BufMut,
) -> Result<(), EncodeError>where
Self: Sized,
fn encode_length_delimited(
&self,
buf: &mut impl BufMut,
) -> Result<(), EncodeError>where
Self: Sized,
Source§fn encode_length_delimited_to_vec(&self) -> Vec<u8> ⓘwhere
Self: Sized,
fn encode_length_delimited_to_vec(&self) -> Vec<u8> ⓘwhere
Self: Sized,
Source§fn decode(buf: impl Buf) -> Result<Self, DecodeError>where
Self: Default,
fn decode(buf: impl Buf) -> Result<Self, DecodeError>where
Self: Default,
Source§fn decode_length_delimited(buf: impl Buf) -> Result<Self, DecodeError>where
Self: Default,
fn decode_length_delimited(buf: impl Buf) -> Result<Self, DecodeError>where
Self: Default,
Source§fn merge(&mut self, buf: impl Buf) -> Result<(), DecodeError>where
Self: Sized,
fn merge(&mut self, buf: impl Buf) -> Result<(), DecodeError>where
Self: Sized,
self
. Read moreSource§fn merge_length_delimited(&mut self, buf: impl Buf) -> Result<(), DecodeError>where
Self: Sized,
fn merge_length_delimited(&mut self, buf: impl Buf) -> Result<(), DecodeError>where
Self: Sized,
self
.impl StructuralPartialEq for EnumRules
Auto Trait Implementations§
impl Freeze for EnumRules
impl RefUnwindSafe for EnumRules
impl Send for EnumRules
impl Sync for EnumRules
impl Unpin for EnumRules
impl UnwindSafe for EnumRules
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request