Struct GraphMl

Source
pub struct GraphMl<G>{ /* private fields */ }
Expand description

GraphML output printer

See the main crate documentation for usage instructions and examples.

Implementations§

Source§

impl<G> GraphMl<G>

Source

pub fn new(graph: G) -> Self

Create a new GraphML printer for the graph.

Source

pub fn pretty_print(self, state: bool) -> Self

Enable or disble pretty printing of the XML.

Pretty printing enables linebreaks and indentation.

Source

pub fn export_edge_weights_display(self) -> Self
where G::EdgeWeight: Display,

Export the edge weights to GraphML.

This uses the Display implementation of the edge weight type. The attribute name defaults to “weight”.

Once set this option cannot be disabled anymore.

Source

pub fn export_edge_weights( self, edge_weight: Box<dyn for<'a> Fn(&'a G::EdgeWeight) -> Vec<(Cow<'static, str>, Cow<'a, str>)>>, ) -> Self

Export the edge weights to GraphML.

This uses a custom conversion function. Each edge can be converted into an arbitray number of attributes. Each attribute is a key-value pair, represented as tuple.

Once set this option cannot be disabled anymore.

§Example

A custom print function for the type (String, u32). It will create two attributes “str attr” and “int attr” containing the string and integer part.

let graph = make_graph();
let graphml = GraphMl::new(&graph).export_edge_weights(Box::new(|edge| {
    let &(ref s, i) = edge;
    vec![
        ("str attr".into(), s[..].into()),
        ("int attr".into(), i.to_string().into()),
    ]
}));

Currently only string attribute types are supported.

Source

pub fn export_node_weights_display(self) -> Self
where G::NodeWeight: Display,

Export the node weights to GraphML.

This uses the Display implementation of the node weight type. The attribute name defaults to “weight”.

Once set this option cannot be disabled anymore.

Source

pub fn export_node_weights( self, node_weight: Box<dyn for<'a> Fn(&'a G::NodeWeight) -> Vec<(Cow<'static, str>, Cow<'a, str>)>>, ) -> Self

Export the node weights to GraphML.

This uses a custom conversion function. Each node can be converted into an arbitray number of attributes. Each attribute is a key-value pair, represented as tuple.

Once set this option cannot be disabled anymore.

§Example

A custom print function for the type (String, u32). It will create two attributes “str attr” and “int attr” containing the string and integer part.

let graph = make_graph();
let graphml = GraphMl::new(&graph).export_node_weights(Box::new(|node| {
    let &(ref s, i) = node;
    vec![
        ("str attr".into(), s[..].into()),
        ("int attr".into(), i.to_string().into()),
    ]
}));

Currently only string attribute types are supported.

Source

pub fn to_writer<W>(&self, writer: W) -> Result<()>
where W: Write,

Write the GraphML file to the given writer.

Trait Implementations§

Source§

impl<G> Debug for GraphMl<G>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<G> Display for GraphMl<G>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<G> Freeze for GraphMl<G>
where G: Freeze,

§

impl<G> !RefUnwindSafe for GraphMl<G>

§

impl<G> !Send for GraphMl<G>

§

impl<G> !Sync for GraphMl<G>

§

impl<G> Unpin for GraphMl<G>
where G: Unpin,

§

impl<G> !UnwindSafe for GraphMl<G>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.