[][src]Trait shoebill::HasPrinter

pub trait HasPrinter<'p> {
    fn printer(&self) -> &Printer<'p>;
fn printer_mut(&mut self) -> &mut Printer<'p>; }

Trait that allows types to allocate and render Docs. See the trait documentation for more details.

The type Printer is itself an instance of HasPrinter so you're free to use that, but the intended purpose of this trait is to allow users to turn one of their own types into a printer by adding a Printer field, then implementing HasPrinter for their type. For example:

 //pub struct MyState<'p> {
 //    ast_elems : Vec<AstElems>,
 //    modifiers : HashMap<Modifier, Defn>,
 //    printer : Printer<'p>
 //}
 //
 //impl<'p> HasPrinter<'p> for MyState<'p> {
 //    fn printer(&self) -> &Printer<'p> {
 //        self
 //    }
 //
 //    fn printer_mut(&mut self) -> &mut Printer<'p> {
 //        self
 //    }
 //}
 // 
 // You can now pass an element of MyState anywhere you need to handle documents.
 // let my_state : &mut MyState<'p> = ...;
 // let doc1 = ...;
 // let doc2 = ...;
 // doc3 = doc1.concat(doc2, my_state);
 // println!("{}", doc3.render(80, my_state));

Required methods

fn printer(&self) -> &Printer<'p>

fn printer_mut(&mut self) -> &mut Printer<'p>

Loading content...

Implementors

impl<'p> HasPrinter<'p> for Printer<'p>[src]

By implementing these two methods on your structure, you can use it as both a document/string allocator, and to render documents. The idea is that if you have some larget structure that holds the state you want to reference while building and rendering docs, you just give it some way of accessing a Printer storage unit and then you no longer really have to think about it.

Loading content...