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.
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
}
}];
}Note that the required rule does not apply. Map keys cannot be unset.
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
ignore is specified.
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
}
}];
}Note that the required rule does not apply. Map values cannot be unset.
Implementations§
Source§impl MapRules
impl MapRules
pub fn length_rules(&self) -> Result<LengthRules, String>
Available on crate feature
protocheck only.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> AnyExt for T
impl<T> AnyExt for T
Source§fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
Attempts to downcast this to
T behind referenceSource§fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
Attempts to downcast this to
T behind mutable referenceSource§fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
Attempts to downcast this to
T behind Rc pointerSource§fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
Attempts to downcast this to
T behind Arc pointerSource§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