pub struct MapRules {
pub min_pairs: Option<u64>,
pub max_pairs: Option<u64>,
pub keys: Option<Box<FieldRules>>,
pub values: Option<Box<FieldRules>>,
}
Expand description
MapRules describe the rules applied to map
values.
Fields§
§min_pairs: Option<u64>
Specifies the minimum number of key-value pairs allowed. If the field has fewer key-value pairs than specified, an error message is generated.
message MyMap {
// The field `value` must have at least 2 key-value pairs.
map<string, string> value = 1 \[(buf.validate.field).map.min_pairs = 2\];
}
max_pairs: Option<u64>
Specifies the maximum number of key-value pairs allowed. If the field has more key-value pairs than specified, an error message is generated.
message MyMap {
// The field `value` must have at most 3 key-value pairs.
map<string, string> value = 1 \[(buf.validate.field).map.max_pairs = 3\];
}
keys: Option<Box<FieldRules>>
Specifies the rules to be applied to each key in the field.
Note that map keys are always considered populated. The required
rule does not apply.
message MyMap {
// The keys in the field `value` must follow the specified rules.
map<string, string> value = 1 [(buf.validate.field).map.keys = {
string: {
min_len: 3
max_len: 10
}
}];
}
values: Option<Box<FieldRules>>
Specifies the rules to be applied to the value of each key in the field. Message values will still have their validations evaluated unless skip is specified here.
Note that map values are always considered populated. The required
rule does not apply.
message MyMap {
// The values in the field `value` must follow the specified rules.
map<string, string> value = 1 [(buf.validate.field).map.values = {
string: {
min_len: 5
max_len: 20
}
}];
}
Implementations§
Trait Implementations§
Source§impl Message for MapRules
impl Message for MapRules
Source§fn encoded_len(&self) -> usize
fn encoded_len(&self) -> usize
Returns the encoded length of the message without a length delimiter.
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,
Encodes the message to a buffer. Read more
Source§fn encode_to_vec(&self) -> Vec<u8> ⓘwhere
Self: Sized,
fn encode_to_vec(&self) -> Vec<u8> ⓘwhere
Self: Sized,
Encodes the message to a newly allocated buffer.
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,
Encodes the message with a length-delimiter to a buffer. Read more
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,
Encodes the message with a length-delimiter to a newly allocated buffer.
Source§fn decode(buf: impl Buf) -> Result<Self, DecodeError>where
Self: Default,
fn decode(buf: impl Buf) -> Result<Self, DecodeError>where
Self: Default,
Decodes an instance of the message from a buffer. Read more
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,
Decodes a length-delimited instance of the message from the buffer.
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,
Decodes an instance of the message from a buffer, and merges it into
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,
Decodes a length-delimited instance of the message from buffer, and
merges it into
self
.impl StructuralPartialEq for MapRules
Auto Trait Implementations§
impl Freeze for MapRules
impl RefUnwindSafe for MapRules
impl Send for MapRules
impl Sync for MapRules
impl Unpin for MapRules
impl UnwindSafe for MapRules
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
Mutably borrows from an owned value. Read more
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>
Wrap the input message
T
in a tonic::Request