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§
Sourcefn to_estring(&self) -> EString
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".