pub trait TStrEq<Rhs>: Sized {
    const EQ: bool;
    const NE: bool = !Self::EQ;

    fn tstr_eq(&self, _other: &Rhs) -> bool { ... }
    fn tstr_ne(&self, _other: &Rhs) -> bool { ... }
}
Available on crate feature cmp_traits only.
Expand description

For equality comparison between type-level strings.

Examples

Basic

use tstr::{TS, TStrEq, tstr_eq, tstr_ne, ts};

use std::cmp::Ordering;

// tstr_eq uses this trait for comparing its TStr arguments for equality
assert!(tstr_eq!(TS!("foo"), TS!("foo")));
// what tstr_eq expands into
assert!(<TS!("foo") as TStrEq<TS!("foo")>>::EQ);

// tstr_ne uses this trait for comparing its TStr arguments for inequality
assert!(tstr_ne!(TS!("foo"), TS!("bar")));
// what tstr_ne expands into
assert!(<TS!("foo") as TStrEq<TS!("bar")>>::NE);

// You can also compare TStrs using the `tstr_eq` and `tstr_ne` methods.
assert!(ts!("foo").tstr_eq(&ts!("foo")));

assert!(ts!("foo").tstr_ne(&ts!("bar")));

Advanced

This uses types from the for_examples module, which can be seen in the docs with the “for_examples” feature.

use tstr::for_examples::Foo;
use tstr::{TStr, TStrEq, TS, ts};

use std::ops::Index;

let this = Foo::new(3, 5, "8");
assert_eq!(get_two(&this, ts!(bar), ts!(qux)), (&3, &"8"));

// Doesn't compile
// assert_eq!(get_two(&this, ts!(bar), ts!(bar)), (&3, &3));

fn get_two<T, A, B>(
    this: &T,
    field_a: TStr<A>,
    field_b: TStr<B>,
) -> (&IndexOut<T, TStr<A>>, &IndexOut<T, TStr<B>>)
where
    T: Index<TStr<A>> + Index<TStr<B>>,
    A: TStrEq<B>,
{
    tstr::Assert::<A, B>::NOT_EQUAL;
    (&this[field_a], &this[field_b])
}


type IndexOut<T, I> = <T as Index<I>>::Output;

Required Associated Constants

Whether Self equals Rhs

Provided Associated Constants

Whether Self is not equal to Rhs

Provided Methods

Returns whether self is equal to other.

Returns whether self is not equal to other.

Implementors