pub struct FieldRules {
pub cel: Vec<Rule>,
pub required: Option<bool>,
pub ignore: Option<i32>,
pub type: Option<Type>,
}
Expand description
FieldRules encapsulates the rules for each type of field. Depending on the field, the correct set should be used to ensure proper validations.
Fields§
§cel: Vec<Rule>
cel
is a repeated field used to represent a textual expression
in the Common Expression Language (CEL) syntax. For more information on
CEL, see our documentation.
message MyMessage {
// The field `value` must be greater than 42.
optional int32 value = 1 [(buf.validate.field).cel = {
id: "my_message.value",
message: "value must be greater than 42",
expression: "this > 42",
}];
}
required: Option<bool>
If required
is true, the field must be populated. A populated field can be
described as “serialized in the wire format,” which includes:
- the following “nullable” fields must be explicitly set to be considered populated:
- singular message fields (whose fields may be unpopulated / default values)
- member fields of a oneof (may be their default value)
- proto3 optional fields (may be their default value)
- proto2 scalar fields (both optional and required)
- proto3 scalar fields must be non-zero to be considered populated
- repeated and map fields must be non-empty to be considered populated
- map keys/values and repeated items are always considered populated
message MyMessage {
// The field `value` must be set to a non-null value.
optional MyOtherMessage value = 1 \[(buf.validate.field).required = true\];
}
ignore: Option<i32>
Skip validation on the field if its value matches the specified criteria. See Ignore enum for details.
message UpdateRequest {
// The uri rule only applies if the field is populated and not an empty
// string.
optional string url = 1 [
(buf.validate.field).ignore = IGNORE_IF_DEFAULT_VALUE,
(buf.validate.field).string.uri = true,
];
}
type: Option<Type>
Implementations§
Source§impl FieldRules
impl FieldRules
Sourcepub fn required(&self) -> bool
pub fn required(&self) -> bool
Returns the value of required
, or the default value if required
is unset.
Sourcepub fn ignore(&self) -> Ignore
pub fn ignore(&self) -> Ignore
Returns the enum value of ignore
, or the default if the field is unset or set to an invalid enum value.
Sourcepub fn set_ignore(&mut self, value: Ignore)
pub fn set_ignore(&mut self, value: Ignore)
Sets ignore
to the provided enum value.
Trait Implementations§
Source§impl Clone for FieldRules
impl Clone for FieldRules
Source§fn clone(&self) -> FieldRules
fn clone(&self) -> FieldRules
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for FieldRules
impl Debug for FieldRules
Source§impl Default for FieldRules
impl Default for FieldRules
Source§impl Message for FieldRules
impl Message for FieldRules
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
.Source§impl PartialEq for FieldRules
impl PartialEq for FieldRules
impl StructuralPartialEq for FieldRules
Auto Trait Implementations§
impl Freeze for FieldRules
impl RefUnwindSafe for FieldRules
impl Send for FieldRules
impl Sync for FieldRules
impl Unpin for FieldRules
impl UnwindSafe for FieldRules
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