Struct tstr::TStr[][src]

pub struct TStr<T>(_);
Expand description

A type-level string type, similar to a &'static str const parameter.

Examples

Accessing Fields

This example demonstrates how you can use TStr to implement a generic accessor trait.

use tstr::TStr;
use tstr::{TS, ts};

fn main() {
    let mut tup = (3, 5, 8);
     
    assert_eq!(tup.get(ts!(0)), &3);
    assert_eq!(tup.get(ts!(1)), &5);
    assert_eq!(tup.get(ts!(2)), &8);

    let old_0 = replace(&mut tup, ts!(0), 333);
    let old_1 = replace(&mut tup, ts!(1), 555);
    let old_2 = replace(&mut tup, ts!(2), 888);
     
    assert_eq!(tup.get(ts!(0)), &333);
    assert_eq!(tup.get(ts!(1)), &555);
    assert_eq!(tup.get(ts!(2)), &888);

    assert_eq!(old_0, 3);
    assert_eq!(old_1, 5);
    assert_eq!(old_2, 8);
     
}

fn replace<T, N>(this: &mut T, name: TStr<N>, replacement: T::Field) -> T::Field
where
    T: Access<TStr<N>>,
    T::Field: Clone,
{
    let ret = this.get(name).clone();
    this.set(name, replacement);
    ret
}


trait Access<N> {
    type Field;

    fn get(&self, _field_name: N) -> &Self::Field;
    fn set(&mut self, _field_name: N, val: Self::Field);
}

impl<A, B, C> Access<TS!(0)> for (A, B, C) {
    type Field = A;

    fn get(&self, _field_name: TS!(0)) -> &A {
        &self.0
    }
    fn set(&mut self, _field_name: TS!(0), val: A){
        self.0 = val;
    }
}

impl<A, B, C> Access<TS!(1)> for (A, B, C) {
    type Field = B;

    fn get(&self, _field_name: TS!(1)) -> &B {
        &self.1
    }
    fn set(&mut self, _field_name: TS!(1), val: B){
        self.1 = val;
    }
}

impl<A, B, C> Access<TS!(2)> for (A, B, C) {
    type Field = C;

    fn get(&self, _field_name: TS!(2)) -> &C {
        &self.2
    }
    fn set(&mut self, _field_name: TS!(2), val: C){
        self.2 = val;
    }
}

Implementations

impl<T> TStr<T>[src]

pub const NEW: Self[src]

Constructs the TStr.

Example

use tstr::{TS, TStr};

type FOO = TS!(foo);

let foo_1: FOO = TStr::NEW;
let foo_2 = FOO::NEW; // The same as the previous statement

impl<T> TStr<T> where
    Self: StrValue
[src]

pub const STR: &'static str[src]

This is supported on crate feature const_generics only.

The &'static str value of this TStr.

Example

use tstr::TS;

type FOO = TS!(foo);
type BAR = TS!(bar);

assert_eq!(FOO::STR, "foo");
assert_eq!(BAR::STR, "bar");

Trait Implementations

impl<T> Clone for TStr<T>[src]

fn clone(&self) -> Self[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<T> Debug for TStr<T>[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl<T> Default for TStr<T>[src]

fn default() -> Self[src]

Returns the “default value” for a type. Read more

impl Index<TStr<___<"bar">>> for Foo[src]

This is supported on crate feature for_examples only.

type Output = u32

The returned type after indexing.

fn index(&self, _: TStr<___<bar>>) -> &u32[src]

Performs the indexing (container[index]) operation. Read more

impl Index<TStr<___<"bar">>> for Bar[src]

This is supported on crate feature for_examples only.

type Output = u32

The returned type after indexing.

fn index(&self, _: TStr<___<bar>>) -> &u32[src]

Performs the indexing (container[index]) operation. Read more

impl Index<TStr<___<"baz">>> for Foo[src]

This is supported on crate feature for_examples only.

type Output = u64

The returned type after indexing.

fn index(&self, _: TStr<___<baz>>) -> &u64[src]

Performs the indexing (container[index]) operation. Read more

impl Index<TStr<___<"baz">>> for Bar[src]

This is supported on crate feature for_examples only.

type Output = bool

The returned type after indexing.

fn index(&self, _: TStr<___<baz>>) -> &bool[src]

Performs the indexing (container[index]) operation. Read more

impl Index<TStr<___<"boom">>> for Bar[src]

This is supported on crate feature for_examples only.

type Output = Option<char>

The returned type after indexing.

fn index(&self, _: TStr<___<boom>>) -> &Option<char>[src]

Performs the indexing (container[index]) operation. Read more

impl Index<TStr<___<"qux">>> for Foo[src]

This is supported on crate feature for_examples only.

type Output = &'static str

The returned type after indexing.

fn index(&self, _: TStr<___<qux>>) -> &&'static str[src]

Performs the indexing (container[index]) operation. Read more

impl IndexMut<TStr<___<"bar">>> for Foo[src]

This is supported on crate feature for_examples only.

fn index_mut(&mut self, _: TStr<___<bar>>) -> &mut u32[src]

Performs the mutable indexing (container[index]) operation. Read more

impl IndexMut<TStr<___<"bar">>> for Bar[src]

This is supported on crate feature for_examples only.

fn index_mut(&mut self, _: TStr<___<bar>>) -> &mut u32[src]

Performs the mutable indexing (container[index]) operation. Read more

impl IndexMut<TStr<___<"baz">>> for Foo[src]

This is supported on crate feature for_examples only.

fn index_mut(&mut self, _: TStr<___<baz>>) -> &mut u64[src]

Performs the mutable indexing (container[index]) operation. Read more

impl IndexMut<TStr<___<"baz">>> for Bar[src]

This is supported on crate feature for_examples only.

fn index_mut(&mut self, _: TStr<___<baz>>) -> &mut bool[src]

Performs the mutable indexing (container[index]) operation. Read more

impl IndexMut<TStr<___<"boom">>> for Bar[src]

This is supported on crate feature for_examples only.

fn index_mut(&mut self, _: TStr<___<boom>>) -> &mut Option<char>[src]

Performs the mutable indexing (container[index]) operation. Read more

impl IndexMut<TStr<___<"qux">>> for Foo[src]

This is supported on crate feature for_examples only.

fn index_mut(&mut self, _: TStr<___<qux>>) -> &mut &'static str[src]

Performs the mutable indexing (container[index]) operation. Read more

impl<T> MakeTStr for TStr<T>[src]

const MAKE: Self[src]

Gets a value of this type

impl<T> Ord for TStr<T>[src]

fn cmp(&self, _other: &Self) -> Ordering[src]

This method returns an Ordering between self and other. Read more

#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]

Compares and returns the maximum of two values. Read more

#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]

Compares and returns the minimum of two values. Read more

#[must_use]
fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]

Restrict a value to a certain interval. Read more

impl<T> PartialEq<TStr<T>> for TStr<T>[src]

fn eq(&self, _other: &Self) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl<T> PartialOrd<TStr<T>> for TStr<T>[src]

fn partial_cmp(&self, _other: &Self) -> Option<Ordering>[src]

This method returns an ordering between self and other values if one exists. Read more

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<const S: &'static str> StrValue for TStr<___<S>>[src]

This is supported on crate feature const_generics only.

const STR: &'static str[src]

The &'static str value of this TStr.

fn to_str(self) -> &'static str[src]

Gets the &'static str value of this TStr.

impl<T> ToUint for TStr<T> where
    T: ToUint
[src]

const U128: u128[src]

The u128 value of the type.

const DIGITS: u32[src]

const USIZE: usize[src]

The usize value of the type. Read more

fn to_usize(&self) -> usize[src]

Gets the usize value of this type Read more

fn to_u128(&self) -> u128[src]

Gets the u128 value of this type

impl<T> Copy for TStr<T>[src]

impl<T> Eq for TStr<T>[src]

Auto Trait Implementations

impl<T> Send for TStr<T>

impl<T> Sync for TStr<T>

impl<T> Unpin for TStr<T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.