use std::io::Write;
pub trait DotExtra<T, A>{
fn dot_from_container_index<F, S1, S2, W>(&self, writer: W, dot_options: S1, f: F)
-> Result<(), std::io::Error>
where
S1: AsRef<str>,
S2: AsRef<str>,
F: FnMut(usize, &A) -> S2,
W: Write;
fn dot_string_from_container_index<F, S1, S2>(&self, dot_options: S1, f: F)
-> String
where
S1: AsRef<str>,
S2: AsRef<str>,
F: FnMut(usize, &A) -> S2
{
let mut s = Vec::new();
self.dot_from_container_index(
&mut s,
dot_options,
f
).unwrap();
String::from_utf8(s).unwrap()
}
fn dot_from_container<F, S1, S2, W>(&self, writer: W, dot_options: S1, mut f: F)
-> Result<(), std::io::Error>
where
S1: AsRef<str>,
S2: AsRef<str>,
F: FnMut(&A) -> S2,
W: Write
{
self.dot_from_container_index(
writer,
dot_options,
|_, a| f(a)
)
}
fn dot_string_from_container<F, S1, S2>(&self, dot_options: S1, f: F)
-> String
where
S1: AsRef<str>,
S2: AsRef<str>,
F: FnMut(&A) -> S2
{
let mut s = Vec::<u8>::new();
self.dot_from_container(
&mut s,
dot_options,
f
).unwrap();
String::from_utf8(s).unwrap()
}
fn dot_from_contained_index<F, S1, S2, W>(&self, writer: W, dot_options: S1, f: F)
-> Result<(), std::io::Error>
where
W: Write,
S1: AsRef<str>,
S2: AsRef<str>,
F: FnMut(usize, &T) -> S2;
fn dot_string_from_contained_index<F, S1, S2>(&self, dot_options: S1, f: F)
-> String
where
S1: AsRef<str>,
S2: AsRef<str>,
F: FnMut(usize, &T) -> S2
{
let mut s = Vec::<u8>::new();
self.dot_from_contained_index(
&mut s,
dot_options,
f
).unwrap();
String::from_utf8(s).unwrap()
}
fn dot_from_contained<F, S1, S2, W>(&self, writer: W, dot_options: S1, mut f: F)
-> Result<(), std::io::Error>
where
W: Write,
S1: AsRef<str>,
S2: AsRef<str>,
F: FnMut(&T) -> S2
{
self.dot_from_contained_index(
writer,
dot_options,
|_, c| f(c)
)
}
fn dot_string_from_contained<F, S1, S2>(&self, dot_options: S1, f: F)
-> String
where
S1: AsRef<str>,
S2: AsRef<str>,
F: FnMut(&T) -> S2
{
let mut s = Vec::<u8>::new();
self.dot_from_contained(
&mut s,
dot_options,
f
).unwrap();
String::from_utf8(s).unwrap()
}
}
pub trait Dot {
fn dot_from_indices<F, W, S1, S2>(&self, writer: W, dot_options: S1, f: F)
-> Result<(), std::io::Error>
where
S1: AsRef<str>,
S2: AsRef<str>,
W: Write,
F: FnMut(usize) -> S2;
fn dot_string_from_indices<F, S1, S2>(&self, dot_options: S1, f: F)
-> String
where
S1: AsRef<str>,
S2: AsRef<str>,
F: FnMut(usize) -> S2
{
let mut s = Vec::new();
self.dot_from_indices(
&mut s,
dot_options,
f
).unwrap();
String::from_utf8(s).unwrap()
}
fn dot_with_indices<S, W>(
&self, writer: W,
dot_options: S
) -> Result<(), std::io::Error>
where
S: AsRef<str>,
W: Write
{
self.dot_from_indices(
writer,
dot_options,
|index| {
index.to_string()
}
)
}
fn dot_string_with_indices<S>(&self, dot_options: S) -> String
where
S: AsRef<str>
{
let mut s = Vec::<u8>::new();
self.dot_with_indices(
&mut s,
dot_options
).unwrap();
String::from_utf8(s).unwrap()
}
fn dot<S, W>(&self, writer: W, dot_options: S) -> Result<(), std::io::Error>
where
S: AsRef<str>,
W: Write
{
self.dot_from_indices(
writer,
dot_options,
|_| {
""
}
)
}
fn dot_string<S>(&self, dot_options: S) -> String
where
S: AsRef<str>
{
let mut s = Vec::<u8>::new();
self.dot(&mut s, dot_options).unwrap();
String::from_utf8(s).unwrap()
}
}