# Example
```rust
// Import Veg
use veg::Veg;
// Create a custom type
struct Point {
x: f32,
y: f32,
}
// Implement a method that creates a Box of the custom type
impl Point {
fn new(x: f32, y: f32) -> Box<Point> {
Box::new(Point { x, y })
}
}
// Implement the veg::Table::row method to define how to print the custom type
impl veg::Table for Point {
fn row(&self) -> Vec<String> {
// Add `$`
[self.x, self.y].iter().map(|x| format!("${x}$")).collect()
// Other ideas:
// - Add 3 decimal places:
//
//[self.x, self.y].iter().map(|x| format!("${x:.3}$")).collect()
// - Do something different for x and y:
//
// vec![
// format!("${:.1}$", self.x),
// format!("${:.4}$", self.y),
//]
// - Just convert to string:
//
//[self.x, self.y].iter().map(|x| x.to_string())).collect()
// ...
}
}
// Create a Veg via the table method with a header definition
// Add a single point
t.push(Point::new(1.0, 1.0));
// Add a bunch of points
t.append(&mut vec![
Point::new(2.0, 4.0),
Point::new(3.0, 9.0),
Point::new(4.0, 16.0),
]);
// Render as markdown
let markdown = t.markdown();
assert_eq!(
markdown,
" \
$1$ | $1$
$2$ | $4$
$3$ | $9$
$4$ | $16$
\
",
);
```
# Changelog
* 0.1.0 (2023-12-11): Initial release
* 0.1.1 (2023-12-11): Add makefile, changelog; fix readme, clippy
* 0.2.0 (2023-12-11): Convert the table function to a method
* 0.2.1 (2023-12-11): Fix readme