Enum spinoso_string::OrdError
source · pub enum OrdError {
InvalidUtf8ByteSequence,
EmptyString,
}
Variants§
InvalidUtf8ByteSequence
The first character in a conventionally UTF-8 String
is an invalid
UTF-8 byte sequence.
EmptyString
The given String
is empty and has no first character.
Implementations§
source§impl OrdError
impl OrdError
sourcepub const EXCEPTION_TYPE: &'static str = "ArgumentError"
pub const EXCEPTION_TYPE: &'static str = "ArgumentError"
OrdError
corresponds to an ArgumentError
Ruby exception.
sourcepub const fn invalid_utf8_byte_sequence() -> Self
pub const fn invalid_utf8_byte_sequence() -> Self
Construct a new OrdError
for an invalid UTF-8 byte sequence.
Only conventionally UTF-8 String
s can generate this error.
Examples
use spinoso_string::{OrdError, String};
let s = String::utf8(b"\xFFabc".to_vec());
assert_eq!(s.ord(), Err(OrdError::invalid_utf8_byte_sequence()));
let s = String::binary(b"\xFFabc".to_vec());
assert_eq!(s.ord(), Ok(0xFF));
sourcepub const fn empty_string() -> Self
pub const fn empty_string() -> Self
Construct a new OrdError
for an empty String
.
Empty String
s have no first character. Empty String
s with any
encoding return this error.
Examples
use spinoso_string::{OrdError, String};
let s = String::utf8(b"\xFFabc".to_vec());
assert_eq!(s.ord(), Err(OrdError::invalid_utf8_byte_sequence()));
sourcepub const fn message(self) -> &'static str
pub const fn message(self) -> &'static str
Error message for this OrdError
.
This message is suitable for generating an ArgumentError
exception
from this OrdError
.
Examples
assert_eq!(
OrdError::invalid_utf8_byte_sequence().message(),
"invalid byte sequence in UTF-8"
);
assert_eq!(OrdError::empty_string().message(), "empty string");
Trait Implementations§
source§impl Error for OrdError
impl Error for OrdError
1.30.0 · source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
The lower-level source of this error, if any. Read more
1.0.0 · source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
source§impl Ord for OrdError
impl Ord for OrdError
source§impl PartialEq<OrdError> for OrdError
impl PartialEq<OrdError> for OrdError
source§impl PartialOrd<OrdError> for OrdError
impl PartialOrd<OrdError> for OrdError
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read more