Trait tstr::StrValue

source ·
pub trait StrValue: Debug + Copy + Default + 'static {
    const STR: &'static str;

    // Provided method
    fn to_str(self) -> &'static str { ... }
}
Available on crate feature const_generics only.
Expand description

For getting the &'static str value of this TStr.

You can use this as the bound for a generic TStr parameter.

§Example

use tstr::{StrValue, ts};

asserts(ts!(foo), ts!(bar), ts!(baz));

fn asserts<A, B, C>(foo: A, bar: B, baz: C)
where
    A: StrValue,
    B: StrValue,
    C: StrValue,
{
    assert_eq!(A::STR, "foo");
    assert_eq!(foo.to_str(), "foo");

    assert_eq!(B::STR, "bar");
    assert_eq!(bar.to_str(), "bar");

    assert_eq!(C::STR, "baz");
    assert_eq!(baz.to_str(), "baz");

}

Required Associated Constants§

source

const STR: &'static str

The &'static str value of this TStr.

Provided Methods§

source

fn to_str(self) -> &'static str

Gets the &'static str value of this TStr.

Object Safety§

This trait is not object safe.

Implementors§