railroad icon indicating copy to clipboard operation
railroad copied to clipboard

Make more node attributes public or add getter methods

Open Danie-1 opened this issue 7 months ago • 1 comments

I would like to use this library for rendering railroad diagrams for regular expressions. I would like to be able to use the current types to represent a railroad diagram, but I don't necessarily always want to use them to generate an svg image. I would like to also have the option to render the nodes as a text diagram, for example:

   Group 1     ANY  
   ╔══════╗    OF   
─┬─╫─abcd─╫─┬─┬a-z┬─
 │ ╚══════╝ │ ╰A-Z╯ 
 ╰───<  <───╯       

In order to do this, I was thinking of making my own trait (similar to your Node trait) which would be used for rendering as text. However, I can't implement the trait on your types, because attributes like "text" on Comment are private. I could get around this issue with some work, but I think it would be much easier if I could access the attributes.

Would you be happy to either have attributes (like text) made public, or have some getter methods like

impl Comment {
    pub fn text(&self) -> &str {
        &self.text
    }
}

?

I would be happy to make a PR for this change, if you are happy with one of the above mentioned solutions.

Danie-1 avatar Jul 11 '24 12:07 Danie-1