|
| 1 | + |
| 2 | +/// Define a private namespace for all its items. |
| 3 | +mod private |
| 4 | +{ |
| 5 | + |
| 6 | + use crate::*; |
| 7 | + pub use iter_tools::{ _IterTrait, IterTrait, BoxedIter }; |
| 8 | + |
| 9 | + use std:: |
| 10 | + { |
| 11 | + hash::Hash, |
| 12 | + fmt, |
| 13 | + }; |
| 14 | + |
| 15 | +// /// Represent directed graph. Can be zero-sized structure if nodes own all the information. |
| 16 | +// pub trait GraphDirected< 'a > |
| 17 | +// { |
| 18 | +// /// Uniquely identify a node. |
| 19 | +// type NodeId : NodeId; |
| 20 | +// /// Node itself. |
| 21 | +// type Node : Node + 'a; |
| 22 | +// |
| 23 | +// /// Get a reference on a node by its id. |
| 24 | +// fn node_ref( &'a self, node_id : Self::NodeId ) -> &'a Self::Node; |
| 25 | +// /// Get id by its node reference. |
| 26 | +// fn node_id( &self, node_id : &'a Self::Node ) -> Self::NodeId; |
| 27 | +// |
| 28 | +// /// Iterate over out nodes of |
| 29 | +// fn node_out_nodes( &'a self, node_id : Self::NodeId ) -> BoxedIter< 'a, Self::NodeId >; |
| 30 | +// |
| 31 | +// } |
| 32 | + |
| 33 | + /// Print directed graph as a tree. |
| 34 | + pub trait GraphDirectedPrintAsTree< 'g > |
| 35 | + where |
| 36 | + Self : abs::GraphDirected< 'g >, |
| 37 | + { |
| 38 | + |
| 39 | + /// Print directed graph as a tree. |
| 40 | + fn _print_as_tree< 'w >( &self, write : &'w mut ( dyn core::fmt::Write + 'w ), node : Self::NodeId ) -> fmt::Result |
| 41 | + { |
| 42 | + // let node = self.node_ref( node ); |
| 43 | + write.write_fmt( format_args!( "{:?}", node ) ) |
| 44 | + } |
| 45 | + |
| 46 | + /// Print directed graph as a tree. |
| 47 | + fn print_as_tree< 'w >( &self, node : Self::NodeId ) -> String |
| 48 | + { |
| 49 | + // let node = self.node_ref( node ); |
| 50 | + let mut result = String::new(); |
| 51 | + self._print_as_tree( &mut result, node ).unwrap(); |
| 52 | + result |
| 53 | + } |
| 54 | + |
| 55 | + } |
| 56 | + |
| 57 | + impl< 'g, T > GraphDirectedPrintAsTree< 'g > for T |
| 58 | + where |
| 59 | + Self : abs::GraphDirected< 'g >, |
| 60 | + { |
| 61 | + } |
| 62 | + |
| 63 | + // impl fmt::Debug for Context< '_ > |
| 64 | + // { |
| 65 | + // fn fmt( &self, c : &mut fmt::Formatter< '_ > ) -> fmt::Result |
| 66 | + // { |
| 67 | + // c |
| 68 | + // .debug_struct( "Context" ) |
| 69 | + // .field( "buf", &"dyn fmt::Write" ) |
| 70 | + // .field( "printer", &self.printer ) |
| 71 | + // .finish() |
| 72 | + // } |
| 73 | + // } |
| 74 | + |
| 75 | +} |
| 76 | + |
| 77 | +crate::mod_interface! |
| 78 | +{ |
| 79 | + own use |
| 80 | + { |
| 81 | + GraphDirectedPrintAsTree, |
| 82 | + }; |
| 83 | +} |
0 commit comments