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

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);

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"));

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"));

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

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.