pub trait TStrOrd<Rhs>: Sized {
    const CMP: Ordering;

    fn tstr_cmp(&self, _other: &Rhs) -> Ordering { ... }
}
Available on crate features const_generics and cmp_traits only.
Expand description

For comparison between two type-level strings, getting the Ordering of Self relative to Rhs.

This is only available with the "const_generics" feature, since it’s only implemented for the &'static str-const-parameter-based representation.

Example

use tstr::{TS, TStrOrd, tstr_cmp, ts};

use std::cmp::Ordering;

const FOO_CMP_FOO: Ordering = {
    // tstr_cmp uses this trait for comparing its TStr arguments for ordering
    tstr_cmp!(TS!("foo"), TS!("foo"))
};
assert_eq!(FOO_CMP_FOO, Ordering::Equal);

const FOO_CMP_FOOOOO: Ordering = {
    // what tstr_cmp expands into
    <TS!("foo") as TStrOrd<TS!("fooooo")>>::CMP
};
assert_eq!(FOO_CMP_FOOOOO, Ordering::Less);

// You can also compare TStrs using the `tstr_cmp` method.
assert_eq!(ts!("foo").tstr_cmp(&ts!("bar")), Ordering::Greater);

// short strings can be greater than longer strings
assert_eq!(ts!("foo").tstr_cmp(&ts!("aaaaaa")), Ordering::Greater);

Required Associated Constants

The Ordering of Self relative to Rhs.

Provided Methods

Compares self and other for ordering.

Implementors