pub enum WellKnown {
Show 18 variants
Email(bool),
Hostname(bool),
Ip(bool),
Ipv4(bool),
Ipv6(bool),
Uri(bool),
UriRef(bool),
Address(bool),
Uuid(bool),
Tuuid(bool),
IpWithPrefixlen(bool),
Ipv4WithPrefixlen(bool),
Ipv6WithPrefixlen(bool),
IpPrefix(bool),
Ipv4Prefix(bool),
Ipv6Prefix(bool),
HostAndPort(bool),
WellKnownRegex(i32),
}
Expand description
WellKnown
rules provide advanced rules against common string
patterns.
Variants§
Email(bool)
email
specifies that the field value must be a valid email address, for
example “foo@example.com”.
Conforms to the definition for a valid email address from the HTML standard. Note that this standard willfully deviates from RFC 5322, which allows many unexpected forms of email addresses and will easily match a typographical error.
If the field value isn’t a valid email address, an error message will be generated.
message MyString {
// value must be a valid email address
string value = 1 \[(buf.validate.field).string.email = true\];
}
Hostname(bool)
hostname
specifies that the field value must be a valid hostname, for
example “foo.example.com”.
A valid hostname follows the rules below:
- The name consists of one or more labels, separated by a dot (“.”).
- Each label can be 1 to 63 alphanumeric characters.
- A label can contain hyphens (“-”), but must not start or end with a hyphen.
- The right-most label must not be digits only.
- The name can have a trailing dot—for example, “foo.example.com.”.
- The name can be 253 characters at most, excluding the optional trailing dot.
If the field value isn’t a valid hostname, an error message will be generated.
message MyString {
// value must be a valid hostname
string value = 1 \[(buf.validate.field).string.hostname = true\];
}
Ip(bool)
ip
specifies that the field value must be a valid IP (v4 or v6) address.
IPv4 addresses are expected in the dotted decimal format—for example, “192.168.5.21”. IPv6 addresses are expected in their text representation—for example, “::1”, or “2001:0DB8:ABCD:0012::0”.
Both formats are well-defined in the internet standard RFC 3986. Zone identifiers for IPv6 addresses (for example, “fe80::a%en1”) are supported.
If the field value isn’t a valid IP address, an error message will be generated.
message MyString {
// value must be a valid IP address
string value = 1 \[(buf.validate.field).string.ip = true\];
}
Ipv4(bool)
ipv4
specifies that the field value must be a valid IPv4 address—for
example “192.168.5.21”. If the field value isn’t a valid IPv4 address, an
error message will be generated.
message MyString {
// value must be a valid IPv4 address
string value = 1 \[(buf.validate.field).string.ipv4 = true\];
}
Ipv6(bool)
ipv6
specifies that the field value must be a valid IPv6 address—for
example “::1”, or “d7a:115c:a1e0:ab12:4843:cd96:626b:430b”. If the field
value is not a valid IPv6 address, an error message will be generated.
message MyString {
// value must be a valid IPv6 address
string value = 1 \[(buf.validate.field).string.ipv6 = true\];
}
Uri(bool)
uri
specifies that the field value must be a valid URI, for example
“https://example.com/foo/bar?baz=quux#frag".
URI is defined in the internet standard RFC 3986. Zone Identifiers in IPv6 address literals are supported (RFC 6874).
If the field value isn’t a valid URI, an error message will be generated.
message MyString {
// value must be a valid URI
string value = 1 \[(buf.validate.field).string.uri = true\];
}
UriRef(bool)
uri_ref
specifies that the field value must be a valid URI Reference—either
a URI such as “https://example.com/foo/bar?baz=quux#frag", or a Relative
Reference such as “./foo/bar?query”.
URI, URI Reference, and Relative Reference are defined in the internet standard RFC 3986. Zone Identifiers in IPv6 address literals are supported (RFC 6874).
If the field value isn’t a valid URI Reference, an error message will be generated.
message MyString {
// value must be a valid URI Reference
string value = 1 \[(buf.validate.field).string.uri_ref = true\];
}
Address(bool)
address
specifies that the field value must be either a valid hostname
(for example, “example.com”), or a valid IP (v4 or v6) address (for example,
“192.168.0.1”, or “::1”). If the field value isn’t a valid hostname or IP,
an error message will be generated.
message MyString {
// value must be a valid hostname, or ip address
string value = 1 \[(buf.validate.field).string.address = true\];
}
Uuid(bool)
uuid
specifies that the field value must be a valid UUID as defined by
RFC 4122. If the
field value isn’t a valid UUID, an error message will be generated.
message MyString {
// value must be a valid UUID
string value = 1 \[(buf.validate.field).string.uuid = true\];
}
Tuuid(bool)
tuuid
(trimmed UUID) specifies that the field value must be a valid UUID as
defined by RFC 4122 with all dashes
omitted. If the field value isn’t a valid UUID without dashes, an error message
will be generated.
message MyString {
// value must be a valid trimmed UUID
string value = 1 \[(buf.validate.field).string.tuuid = true\];
}
IpWithPrefixlen(bool)
ip_with_prefixlen
specifies that the field value must be a valid IP
(v4 or v6) address with prefix length—for example, “192.168.5.21/16” or
“2001:0DB8:ABCD:0012::F1/64”. If the field value isn’t a valid IP with
prefix length, an error message will be generated.
message MyString {
// value must be a valid IP with prefix length
string value = 1 \[(buf.validate.field).string.ip_with_prefixlen = true\];
}
Ipv4WithPrefixlen(bool)
ipv4_with_prefixlen
specifies that the field value must be a valid
IPv4 address with prefix length—for example, “192.168.5.21/16”. If the
field value isn’t a valid IPv4 address with prefix length, an error
message will be generated.
message MyString {
// value must be a valid IPv4 address with prefix length
string value = 1 \[(buf.validate.field).string.ipv4_with_prefixlen = true\];
}
Ipv6WithPrefixlen(bool)
ipv6_with_prefixlen
specifies that the field value must be a valid
IPv6 address with prefix length—for example, “2001:0DB8:ABCD:0012::F1/64”.
If the field value is not a valid IPv6 address with prefix length,
an error message will be generated.
message MyString {
// value must be a valid IPv6 address prefix length
string value = 1 \[(buf.validate.field).string.ipv6_with_prefixlen = true\];
}
IpPrefix(bool)
ip_prefix
specifies that the field value must be a valid IP (v4 or v6)
prefix—for example, “192.168.0.0/16” or “2001:0DB8:ABCD:0012::0/64”.
The prefix must have all zeros for the unmasked bits. For example, “2001:0DB8:ABCD:0012::0/64” designates the left-most 64 bits for the prefix, and the remaining 64 bits must be zero.
If the field value isn’t a valid IP prefix, an error message will be generated.
message MyString {
// value must be a valid IP prefix
string value = 1 \[(buf.validate.field).string.ip_prefix = true\];
}
Ipv4Prefix(bool)
ipv4_prefix
specifies that the field value must be a valid IPv4
prefix, for example “192.168.0.0/16”.
The prefix must have all zeros for the unmasked bits. For example, “192.168.0.0/16” designates the left-most 16 bits for the prefix, and the remaining 16 bits must be zero.
If the field value isn’t a valid IPv4 prefix, an error message will be generated.
message MyString {
// value must be a valid IPv4 prefix
string value = 1 \[(buf.validate.field).string.ipv4_prefix = true\];
}
Ipv6Prefix(bool)
ipv6_prefix
specifies that the field value must be a valid IPv6 prefix—for
example, “2001:0DB8:ABCD:0012::0/64”.
The prefix must have all zeros for the unmasked bits. For example, “2001:0DB8:ABCD:0012::0/64” designates the left-most 64 bits for the prefix, and the remaining 64 bits must be zero.
If the field value is not a valid IPv6 prefix, an error message will be generated.
message MyString {
// value must be a valid IPv6 prefix
string value = 1 \[(buf.validate.field).string.ipv6_prefix = true\];
}
HostAndPort(bool)
host_and_port
specifies that the field value must be valid host/port
pair—for example, “example.com:8080”.
The host can be one of:
- An IPv4 address in dotted decimal format—for example, “192.168.5.21”.
- An IPv6 address enclosed in square brackets—for example, “[2001:0DB8:ABCD:0012::F1]”.
- A hostname—for example, “example.com”.
The port is separated by a colon. It must be non-empty, with a decimal number in the range of 0-65535, inclusive.
WellKnownRegex(i32)
well_known_regex
specifies a common well-known pattern
defined as a regex. If the field value doesn’t match the well-known
regex, an error message will be generated.
message MyString {
// value must be a valid HTTP header value
string value = 1 \[(buf.validate.field).string.well_known_regex = KNOWN_REGEX_HTTP_HEADER_VALUE\];
}
§KnownRegex
well_known_regex
contains some well-known patterns.
Implementations§
Source§impl WellKnown
impl WellKnown
Sourcepub fn merge(
field: &mut Option<WellKnown>,
tag: u32,
wire_type: WireType,
buf: &mut impl Buf,
ctx: DecodeContext,
) -> Result<(), DecodeError>
pub fn merge( field: &mut Option<WellKnown>, tag: u32, wire_type: WireType, buf: &mut impl Buf, ctx: DecodeContext, ) -> Result<(), DecodeError>
Decodes an instance of the message from a buffer, and merges it into self.
Sourcepub fn encoded_len(&self) -> usize
pub fn encoded_len(&self) -> usize
Returns the encoded length of the message without a length delimiter.
Trait Implementations§
impl Copy for WellKnown
impl StructuralPartialEq for WellKnown
Auto Trait Implementations§
impl Freeze for WellKnown
impl RefUnwindSafe for WellKnown
impl Send for WellKnown
impl Sync for WellKnown
impl Unpin for WellKnown
impl UnwindSafe for WellKnown
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