Skip to main content

ValT

Trait ValT 

Source
pub trait ValT:
    ValT
    + Ord
    + From<f64>
    + From<usize> {
    // Required methods
    fn into_seq<S: FromIterator<Self>>(self) -> Result<S, Self>;
    fn is_int(&self) -> bool;
    fn as_isize(&self) -> Option<isize>;
    fn as_f64(&self) -> Option<f64>;
    fn is_utf8_str(&self) -> bool;
    fn as_bytes(&self) -> Option<&[u8]>;
    fn as_sub_str(&self, sub: &[u8]) -> Self;
    fn from_utf8_bytes(b: impl AsRef<[u8]> + Send + 'static) -> Self;

    // Provided methods
    fn as_utf8_bytes(&self) -> Option<&[u8]> { ... }
    fn try_as_bytes(&self) -> Result<&[u8], Error<Self>> { ... }
    fn try_as_utf8_bytes(&self) -> Result<&[u8], Error<Self>> { ... }
}
Expand description

Values that the standard library can operate on.

Required Methods§

Source

fn into_seq<S: FromIterator<Self>>(self) -> Result<S, Self>

Convert an array into a sequence.

This returns the original value as Err if it is not an array.

Source

fn is_int(&self) -> bool

True if the value is integer.

Source

fn as_isize(&self) -> Option<isize>

Use the value as machine-sized integer.

If this function returns Some(_), then Self::is_int must return true. However, the other direction must not necessarily be the case, because there may be integer values that are not representable by isize.

Source

fn as_f64(&self) -> Option<f64>

Use the value as floating-point number.

This succeeds for all numeric values, rounding too large/small ones to +/- Infinity.

Source

fn is_utf8_str(&self) -> bool

True if the value is interpreted as UTF-8 string.

Source

fn as_bytes(&self) -> Option<&[u8]>

If the value is a string (whatever its interpretation), return its bytes.

Source

fn as_sub_str(&self, sub: &[u8]) -> Self

If the value is a string and sub points to a slice of the string, shorten the string to sub, else panic.

Source

fn from_utf8_bytes(b: impl AsRef<[u8]> + Send + 'static) -> Self

Interpret bytes as UTF-8 string value.

Provided Methods§

Source

fn as_utf8_bytes(&self) -> Option<&[u8]>

If the value is interpreted as UTF-8 string, return its bytes.

Source

fn try_as_bytes(&self) -> Result<&[u8], Error<Self>>

If the value is a string (whatever its interpretation), return its bytes, else fail.

Source

fn try_as_utf8_bytes(&self) -> Result<&[u8], Error<Self>>

If the value is interpreted as UTF-8 string, return its bytes, else fail.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§