#[cfg(feature = "parsing")]
use svgparser::TextFrame;
use WriteOptions;
#[cfg(feature = "parsing")]
pub trait FromStream: Sized {
type Err;
fn from_stream(s: TextFrame) -> Result<Self, Self::Err>;
fn from_str(data: &str) -> Result<Self, Self::Err> {
FromStream::from_stream(TextFrame::from_str(data))
}
}
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 WriteToString: 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 WriteToString for $t {}
)
}