pub trait StringArgument: Sealed + Sized {
// Required methods
fn require_non_blank(self, path: &str) -> ArgumentResult<Self>;
fn require_byte_len(
self,
path: &str,
expected: usize,
) -> ArgumentResult<Self>;
fn require_byte_len_at_least(
self,
path: &str,
min: usize,
) -> ArgumentResult<Self>;
fn require_byte_len_at_most(
self,
path: &str,
max: usize,
) -> ArgumentResult<Self>;
fn require_byte_len_in(
self,
path: &str,
min: usize,
max: usize,
) -> ArgumentResult<Self>;
fn require_char_count(
self,
path: &str,
expected: usize,
) -> ArgumentResult<Self>;
fn require_char_count_at_least(
self,
path: &str,
min: usize,
) -> ArgumentResult<Self>;
fn require_char_count_at_most(
self,
path: &str,
max: usize,
) -> ArgumentResult<Self>;
fn require_char_count_in(
self,
path: &str,
min: usize,
max: usize,
) -> ArgumentResult<Self>;
}Expand description
Validates string arguments while preserving ownership or borrowing.
Byte-length methods count UTF-8 bytes, while character-count methods count
Unicode scalar values. Every successful method returns the original value
without cloning it. String contents are inspected but never captured in an
error. Length failures use LengthMetric::Bytes for byte methods and
LengthMetric::UnicodeScalars for character-count methods.
The trait is sealed and implemented only for String and &str.
Required Methods§
Sourcefn require_non_blank(self, path: &str) -> ArgumentResult<Self>
fn require_non_blank(self, path: &str) -> ArgumentResult<Self>
Requires this string to contain at least one non-whitespace character.
Success returns the original value without cloning. Empty strings and
strings whose Unicode scalar values are all whitespace return
ArgumentErrorKind::Blank at path.
Sourcefn require_byte_len(self, path: &str, expected: usize) -> ArgumentResult<Self>
fn require_byte_len(self, path: &str, expected: usize) -> ArgumentResult<Self>
Requires this string to contain exactly expected UTF-8 bytes.
Success returns the original value without cloning. A different byte
length returns ArgumentErrorKind::Length at path.
Sourcefn require_byte_len_at_least(
self,
path: &str,
min: usize,
) -> ArgumentResult<Self>
fn require_byte_len_at_least( self, path: &str, min: usize, ) -> ArgumentResult<Self>
Requires this string to contain at least min UTF-8 bytes.
Success returns the original value without cloning. A smaller byte
length returns ArgumentErrorKind::Length at path.
Sourcefn require_byte_len_at_most(
self,
path: &str,
max: usize,
) -> ArgumentResult<Self>
fn require_byte_len_at_most( self, path: &str, max: usize, ) -> ArgumentResult<Self>
Requires this string to contain at most max UTF-8 bytes.
Success returns the original value without cloning. A larger byte
length returns ArgumentErrorKind::Length at path.
Sourcefn require_byte_len_in(
self,
path: &str,
min: usize,
max: usize,
) -> ArgumentResult<Self>
fn require_byte_len_in( self, path: &str, min: usize, max: usize, ) -> ArgumentResult<Self>
Requires this string’s UTF-8 byte length to lie in min..=max.
The range is validated before the string length. If min > max, this
returns ArgumentErrorKind::InvalidLengthConstraint at path;
otherwise, an out-of-range length returns
ArgumentErrorKind::Length. Success returns the original value
without cloning.
Sourcefn require_char_count(self, path: &str, expected: usize) -> ArgumentResult<Self>
fn require_char_count(self, path: &str, expected: usize) -> ArgumentResult<Self>
Requires this string to contain exactly expected Unicode scalar
values.
Success returns the original value without cloning. A different scalar
count returns ArgumentErrorKind::Length at path.
Sourcefn require_char_count_at_least(
self,
path: &str,
min: usize,
) -> ArgumentResult<Self>
fn require_char_count_at_least( self, path: &str, min: usize, ) -> ArgumentResult<Self>
Requires this string to contain at least min Unicode scalar values.
Success returns the original value without cloning. A smaller scalar
count returns ArgumentErrorKind::Length at path.
Sourcefn require_char_count_at_most(
self,
path: &str,
max: usize,
) -> ArgumentResult<Self>
fn require_char_count_at_most( self, path: &str, max: usize, ) -> ArgumentResult<Self>
Requires this string to contain at most max Unicode scalar values.
Success returns the original value without cloning. A larger scalar
count returns ArgumentErrorKind::Length at path.
Sourcefn require_char_count_in(
self,
path: &str,
min: usize,
max: usize,
) -> ArgumentResult<Self>
fn require_char_count_in( self, path: &str, min: usize, max: usize, ) -> ArgumentResult<Self>
Requires this string’s Unicode scalar count to lie in min..=max.
The range is validated before the character count. If min > max, this
returns ArgumentErrorKind::InvalidLengthConstraint at path;
otherwise, an out-of-range count returns ArgumentErrorKind::Length.
Success returns the original value without cloning.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl StringArgument for &str
impl StringArgument for &str
Source§fn require_non_blank(self, path: &str) -> ArgumentResult<Self>
fn require_non_blank(self, path: &str) -> ArgumentResult<Self>
Validates Unicode blankness and returns the original borrow.
path identifies a ArgumentErrorKind::Blank failure.
Source§fn require_byte_len(self, path: &str, expected: usize) -> ArgumentResult<Self>
fn require_byte_len(self, path: &str, expected: usize) -> ArgumentResult<Self>
Validates the exact UTF-8 byte length and returns the original borrow.
A mismatch returns ArgumentErrorKind::Length at path.
Source§fn require_byte_len_at_least(
self,
path: &str,
min: usize,
) -> ArgumentResult<Self>
fn require_byte_len_at_least( self, path: &str, min: usize, ) -> ArgumentResult<Self>
Validates the minimum UTF-8 byte length and returns the original borrow.
A value below min returns ArgumentErrorKind::Length at path.
Source§fn require_byte_len_at_most(
self,
path: &str,
max: usize,
) -> ArgumentResult<Self>
fn require_byte_len_at_most( self, path: &str, max: usize, ) -> ArgumentResult<Self>
Validates the maximum UTF-8 byte length and returns the original borrow.
A value above max returns ArgumentErrorKind::Length at path.
Source§fn require_byte_len_in(
self,
path: &str,
min: usize,
max: usize,
) -> ArgumentResult<Self>
fn require_byte_len_in( self, path: &str, min: usize, max: usize, ) -> ArgumentResult<Self>
Validates an inclusive UTF-8 byte-length range and returns the borrow.
min > max returns ArgumentErrorKind::InvalidLengthConstraint at
path; an out-of-range value returns ArgumentErrorKind::Length.
Source§fn require_char_count(self, path: &str, expected: usize) -> ArgumentResult<Self>
fn require_char_count(self, path: &str, expected: usize) -> ArgumentResult<Self>
Validates the exact Unicode scalar count and returns the original borrow.
A mismatch returns ArgumentErrorKind::Length at path.
Source§fn require_char_count_at_least(
self,
path: &str,
min: usize,
) -> ArgumentResult<Self>
fn require_char_count_at_least( self, path: &str, min: usize, ) -> ArgumentResult<Self>
Validates the minimum Unicode scalar count and returns the original borrow.
A count below min returns ArgumentErrorKind::Length at path.
Source§fn require_char_count_at_most(
self,
path: &str,
max: usize,
) -> ArgumentResult<Self>
fn require_char_count_at_most( self, path: &str, max: usize, ) -> ArgumentResult<Self>
Validates the maximum Unicode scalar count and returns the original borrow.
A count above max returns ArgumentErrorKind::Length at path.
Source§fn require_char_count_in(
self,
path: &str,
min: usize,
max: usize,
) -> ArgumentResult<Self>
fn require_char_count_in( self, path: &str, min: usize, max: usize, ) -> ArgumentResult<Self>
Validates an inclusive Unicode scalar-count range and returns the borrow.
min > max returns ArgumentErrorKind::InvalidLengthConstraint at
path; an out-of-range count returns ArgumentErrorKind::Length.
Source§impl StringArgument for String
impl StringArgument for String
Source§fn require_non_blank(self, path: &str) -> ArgumentResult<Self>
fn require_non_blank(self, path: &str) -> ArgumentResult<Self>
Validates Unicode blankness and returns the original owned string.
path identifies a ArgumentErrorKind::Blank failure.
Source§fn require_byte_len(self, path: &str, expected: usize) -> ArgumentResult<Self>
fn require_byte_len(self, path: &str, expected: usize) -> ArgumentResult<Self>
Validates the exact UTF-8 byte length and returns the owned string.
A mismatch returns ArgumentErrorKind::Length at path.
Source§fn require_byte_len_at_least(
self,
path: &str,
min: usize,
) -> ArgumentResult<Self>
fn require_byte_len_at_least( self, path: &str, min: usize, ) -> ArgumentResult<Self>
Validates the minimum UTF-8 byte length and returns the owned string.
A value below min returns ArgumentErrorKind::Length at path.
Source§fn require_byte_len_at_most(
self,
path: &str,
max: usize,
) -> ArgumentResult<Self>
fn require_byte_len_at_most( self, path: &str, max: usize, ) -> ArgumentResult<Self>
Validates the maximum UTF-8 byte length and returns the owned string.
A value above max returns ArgumentErrorKind::Length at path.
Source§fn require_byte_len_in(
self,
path: &str,
min: usize,
max: usize,
) -> ArgumentResult<Self>
fn require_byte_len_in( self, path: &str, min: usize, max: usize, ) -> ArgumentResult<Self>
Validates an inclusive UTF-8 byte-length range and returns the string.
min > max returns ArgumentErrorKind::InvalidLengthConstraint at
path; an out-of-range value returns ArgumentErrorKind::Length.
Source§fn require_char_count(self, path: &str, expected: usize) -> ArgumentResult<Self>
fn require_char_count(self, path: &str, expected: usize) -> ArgumentResult<Self>
Validates the exact Unicode scalar count and returns the owned string.
A mismatch returns ArgumentErrorKind::Length at path.
Source§fn require_char_count_at_least(
self,
path: &str,
min: usize,
) -> ArgumentResult<Self>
fn require_char_count_at_least( self, path: &str, min: usize, ) -> ArgumentResult<Self>
Validates the minimum Unicode scalar count and returns the owned string.
A count below min returns ArgumentErrorKind::Length at path.
Source§fn require_char_count_at_most(
self,
path: &str,
max: usize,
) -> ArgumentResult<Self>
fn require_char_count_at_most( self, path: &str, max: usize, ) -> ArgumentResult<Self>
Validates the maximum Unicode scalar count and returns the owned string.
A count above max returns ArgumentErrorKind::Length at path.
Source§fn require_char_count_in(
self,
path: &str,
min: usize,
max: usize,
) -> ArgumentResult<Self>
fn require_char_count_in( self, path: &str, min: usize, max: usize, ) -> ArgumentResult<Self>
Validates an inclusive Unicode scalar-count range and returns the string.
min > max returns ArgumentErrorKind::InvalidLengthConstraint at
path; an out-of-range count returns ArgumentErrorKind::Length.