use std::str::FromStr;
use svgparser::{
StrSpan,
};
use WriteOptions;
pub trait ParseFromSpan: FromStr {
type Err;
fn from_span(s: StrSpan) -> Result<Self, <Self as ParseFromSpan>::Err>;
}
macro_rules! impl_from_str {
($t:ty) => (
impl FromStr for $t {
type Err = ParseError;
fn from_str(s: &str) -> Result<$t, ParseError> {
ParseFromSpan::from_span(StrSpan::from_str(s))
}
}
)
}
pub trait WriteBuffer {
fn write_buf_opt(&self, opt: &WriteOptions, buf: &mut Vec<u8>);
fn write_buf(&self, buf: &mut Vec<u8>) {
self.write_buf_opt(&WriteOptions::default(), buf);
}
}
pub trait ToStringWithOptions: WriteBuffer {
fn to_string_with_opt(&self, opt: &WriteOptions) -> String {
let mut out = Vec::with_capacity(32);
self.write_buf_opt(opt, &mut out);
String::from_utf8(out).unwrap()
}
}
macro_rules! impl_display {
($t:ty) => (
impl fmt::Display for $t {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use std::str;
let mut out = Vec::with_capacity(32);
self.write_buf(&mut out);
write!(f, "{}", str::from_utf8(&out).unwrap())
}
}
impl ToStringWithOptions for $t {}
)
}