#[repr(i32)]pub enum Ignore {
Unspecified = 0,
IfUnpopulated = 1,
IfDefaultValue = 2,
Always = 3,
}
Expand description
Specifies how FieldRules.ignore behaves. See the documentation for FieldRules.required for definitions of “populated” and “nullable”.
Variants§
Unspecified = 0
Validation is only skipped if it’s an unpopulated nullable fields.
syntax="proto3";
message Request {
// The uri rule applies to any value, including the empty string.
string foo = 1 [
(buf.validate.field).string.uri = true
];
// The uri rule only applies if the field is set, including if it's
// set to the empty string.
optional string bar = 2 [
(buf.validate.field).string.uri = true
];
// The min_items rule always applies, even if the list is empty.
repeated string baz = 3 [
(buf.validate.field).repeated.min_items = 3
];
// The custom CEL rule applies only if the field is set, including if
// it's the "zero" value of that message.
SomeMessage quux = 4 [
(buf.validate.field).cel = {/* ... */}
];
}
IfUnpopulated = 1
Validation is skipped if the field is unpopulated. This rule is redundant if the field is already nullable.
syntax="proto3
message Request {
// The uri rule applies only if the value is not the empty string.
string foo = 1 [
(buf.validate.field).string.uri = true,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED
];
// IGNORE_IF_UNPOPULATED is equivalent to IGNORE_UNSPECIFIED in this
// case: the uri rule only applies if the field is set, including if
// it's set to the empty string.
optional string bar = 2 [
(buf.validate.field).string.uri = true,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED
];
// The min_items rule only applies if the list has at least one item.
repeated string baz = 3 [
(buf.validate.field).repeated.min_items = 3,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED
];
// IGNORE_IF_UNPOPULATED is equivalent to IGNORE_UNSPECIFIED in this
// case: the custom CEL rule applies only if the field is set, including
// if it's the "zero" value of that message.
SomeMessage quux = 4 [
(buf.validate.field).cel = {/* ... */},
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED
];
}
IfDefaultValue = 2
Validation is skipped if the field is unpopulated or if it is a nullable field populated with its default value. This is typically the zero or empty value, but proto2 scalars support custom defaults. For messages, the default is a non-null message with all its fields unpopulated.
syntax="proto3
message Request {
// IGNORE_IF_DEFAULT_VALUE is equivalent to IGNORE_IF_UNPOPULATED in
// this case; the uri rule applies only if the value is not the empty
// string.
string foo = 1 [
(buf.validate.field).string.uri = true,
(buf.validate.field).ignore = IGNORE_IF_DEFAULT_VALUE
];
// The uri rule only applies if the field is set to a value other than
// the empty string.
optional string bar = 2 [
(buf.validate.field).string.uri = true,
(buf.validate.field).ignore = IGNORE_IF_DEFAULT_VALUE
];
// IGNORE_IF_DEFAULT_VALUE is equivalent to IGNORE_IF_UNPOPULATED in
// this case; the min_items rule only applies if the list has at least
// one item.
repeated string baz = 3 [
(buf.validate.field).repeated.min_items = 3,
(buf.validate.field).ignore = IGNORE_IF_DEFAULT_VALUE
];
// The custom CEL rule only applies if the field is set to a value other
// than an empty message (i.e., fields are unpopulated).
SomeMessage quux = 4 [
(buf.validate.field).cel = {/* ... */},
(buf.validate.field).ignore = IGNORE_IF_DEFAULT_VALUE
];
}
This rule is affected by proto2 custom default values:
syntax="proto2";
message Request {
// The gt rule only applies if the field is set and it's value is not
the default (i.e., not -42). The rule even applies if the field is set
to zero since the default value differs.
optional int32 value = 1 [
default = -42,
(buf.validate.field).int32.gt = 0,
(buf.validate.field).ignore = IGNORE_IF_DEFAULT_VALUE
];
}
Always = 3
The validation rules of this field will be skipped and not evaluated. This is useful for situations that necessitate turning off the rules of a field containing a message that may not make sense in the current context, or to temporarily disable rules during development.
message MyMessage {
// The field's rules will always be ignored, including any validation's
// on value's fields.
MyOtherMessage value = 1 [
(buf.validate.field).ignore = IGNORE_ALWAYS];
}
Implementations§
Source§impl Ignore
impl Ignore
Sourcepub fn as_str_name(&self) -> &'static str
pub fn as_str_name(&self) -> &'static str
String value of the enum field names used in the ProtoBuf definition.
The values are not transformed in any way and thus are considered stable (if the ProtoBuf definition does not change) and safe for programmatic use.
Sourcepub fn from_str_name(value: &str) -> Option<Self>
pub fn from_str_name(value: &str) -> Option<Self>
Creates an enum from field names used in the ProtoBuf definition.
Trait Implementations§
Source§impl Ord for Ignore
impl Ord for Ignore
Source§impl PartialOrd for Ignore
impl PartialOrd for Ignore
impl Copy for Ignore
impl Eq for Ignore
impl StructuralPartialEq for Ignore
Auto Trait Implementations§
impl Freeze for Ignore
impl RefUnwindSafe for Ignore
impl Send for Ignore
impl Sync for Ignore
impl Unpin for Ignore
impl UnwindSafe for Ignore
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<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.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