Struct id_tree_layout::layouter::Layouter
source · [−]pub struct Layouter<'a, 'b, 'c, T>where
T: Visualize,{ /* private fields */ }
Expand description
The Layouter type provides a simple builder mechanism with a fluent API.
Implementations
sourceimpl<'a, 'b, 'c, T> Layouter<'a, 'b, 'c, T>where
T: Visualize,
impl<'a, 'b, 'c, T> Layouter<'a, 'b, 'c, T>where
T: Visualize,
sourcepub fn new(tree: &'a Tree<T>) -> Self
pub fn new(tree: &'a Tree<T>) -> Self
Creates a new Layouter with the required tree.
use id_tree_layout::{Layouter, Visualize};
use id_tree::{Tree, TreeBuilder};
struct MyNodeData(i32);
impl Visualize for MyNodeData {
fn visualize(&self) -> std::string::String { self.0.to_string() }
fn emphasize(&self) -> bool { false }
}
let tree: Tree<MyNodeData> = TreeBuilder::new().build();
let layouter = Layouter::new(&tree);
sourcepub fn with_file_path(self, path: &'c Path) -> Self
pub fn with_file_path(self, path: &'c Path) -> Self
Sets the path of the output file on the layouter.
use id_tree_layout::{Layouter, Visualize};
use id_tree::{Tree, TreeBuilder};
use std::path::Path;
struct MyNodeData(i32);
impl Visualize for MyNodeData {
fn visualize(&self) -> std::string::String { self.0.to_string() }
fn emphasize(&self) -> bool { false }
}
let tree: Tree<MyNodeData> = TreeBuilder::new().build();
let layouter = Layouter::new(&tree)
.with_file_path(Path::new("test.svg"));
sourcepub fn with_drawer(self, drawer: &'b dyn Drawer) -> Self
pub fn with_drawer(self, drawer: &'b dyn Drawer) -> Self
Sets a different drawer when you don’t want to use the default svg-drawer. If this method is not called the crate’s own svg-drawer is used.
use id_tree_layout::{Drawer, Layouter, PlacedTreeItem, Visualize};
use id_tree_layout::drawer::Result;
use id_tree::{Tree, TreeBuilder};
use std::path::Path;
struct NilDrawer;
impl Drawer for NilDrawer {
fn draw(&self, _file_name: &Path, _embedding: &[PlacedTreeItem]) -> Result {
Ok(())
}
}
struct MyNodeData(i32);
impl Visualize for MyNodeData {
fn visualize(&self) -> std::string::String { self.0.to_string() }
fn emphasize(&self) -> bool { false }
}
let tree: Tree<MyNodeData> = TreeBuilder::new().build();
let drawer = NilDrawer;
let layouter = Layouter::new(&tree)
.with_drawer(&drawer)
.with_file_path(Path::new("test.svg"));
sourcepub fn write(&self) -> Result
pub fn write(&self) -> Result
When the layouter instance is fully configured this method invokes the necessary embedding functionality and uses the drawer which writes the result to the output file in its own output format.
use id_tree_layout::{Layouter, Visualize};
use id_tree::{Tree, TreeBuilder};
use std::path::Path;
struct MyNodeData(i32);
impl Visualize for MyNodeData {
fn visualize(&self) -> std::string::String { self.0.to_string() }
fn emphasize(&self) -> bool { false }
}
let tree: Tree<MyNodeData> = TreeBuilder::new().build();
Layouter::new(&tree)
.with_file_path(Path::new("test.svg"))
.write().expect("Failed writing layout")
Auto Trait Implementations
impl<'a, 'b, 'c, T> !RefUnwindSafe for Layouter<'a, 'b, 'c, T>
impl<'a, 'b, 'c, T> !Send for Layouter<'a, 'b, 'c, T>
impl<'a, 'b, 'c, T> !Sync for Layouter<'a, 'b, 'c, T>
impl<'a, 'b, 'c, T> Unpin for Layouter<'a, 'b, 'c, T>
impl<'a, 'b, 'c, T> !UnwindSafe for Layouter<'a, 'b, 'c, T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more