Skip to main content

ToEString

Trait ToEString 

Source
pub trait ToEString {
    // Required method
    fn to_estring(&self) -> EString;
}
Expand description

Format this type and wrap into EString.

ToEString’s to_estring method is often used implicitly, through EString’s from.

§Examples

Basic implementation of ToEString on an example Point.

use std::fmt::Write;
use estring::{EString, ToEString};

#[derive(Debug, PartialEq)]
struct Point {
    x: i32,
    y: i32,
}

impl ToEString for Point {
    fn to_estring(&self) -> EString {
        let mut res = String::new();
        write!(res, "({},{})", self.x, self.y)
            .ok()
            .expect("Cannot format Point into EString");
        EString(res)
    }
}

let point = Point { x: 1, y: 2 };
assert_eq!(point.to_estring(), EString::from("(1,2)"));

Required Methods§

Source

fn to_estring(&self) -> EString

Format this type and returns EString.

§Examples
use estring::{EString, ToEString};

let i = 5;
let five = EString::from(5);
assert_eq!(five, i.to_estring());

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl ToEString for String

Source§

impl ToEString for bool

Source§

impl ToEString for f32

Source§

impl ToEString for f64

Source§

impl ToEString for i8

Source§

impl ToEString for i16

Source§

impl ToEString for i32

Source§

impl ToEString for i64

Source§

impl ToEString for i128

Source§

impl ToEString for isize

Source§

impl ToEString for u8

Source§

impl ToEString for u16

Source§

impl ToEString for u32

Source§

impl ToEString for u64

Source§

impl ToEString for u128

Source§

impl ToEString for usize

Source§

impl<'a> ToEString for &'a str

Source§

impl<T> ToEString for Option<T>
where T: ToEString,

Implementors§

Source§

impl<A, B, C, const S1: char, const S2: char> ToEString for Trio<A, S1, B, S2, C>
where A: ToEString, B: ToEString, C: ToEString,

Source§

impl<A, B, const S1: char> ToEString for Pair<A, S1, B>
where A: ToEString, B: ToEString,

Source§

impl<T, const SEP: char> ToEString for SepVec<T, SEP>
where T: ToEString,

Source§

impl<T> ToEString for Trim<T>
where T: ToEString,