pub struct PlantUmlContent { /* private fields */ }
Expand description

A token sequence that is a single PlantUML diagram, that is, from the StartLine to the EndLine (lines inclusive).

Examples

use plantuml_parser::{IncludesCollections, PlantUmlContent, PlantUmlFileData};

let data_for_include = r#"
@startuml
title Example Title Included
Bob -> Alice: Hi
@enduml
"#;

let data = r#"
@startuml
title Example Title
Alice -> Bob: Hello
!include foo.puml!0
@enduml
"#;

let filedata = PlantUmlFileData::parse_from_str(data)?;
let content: &PlantUmlContent = filedata.get(0).unwrap();

// Parsed and collected `!include`, `title`, `header`, `footer`
let include_0 = content.includes().get(0).unwrap();
assert!(content.includes().get(1).is_none());
assert_eq!(content.includes().len(), 1);
assert_eq!(include_0.filepath(), "foo.puml");
assert_eq!(include_0.index(), Some(0));
assert_eq!(include_0.id(), Some("0"));

let title_0 = content.titles().get(0).unwrap();
assert!(content.titles().get(1).is_none());
assert_eq!(content.titles().len(), 1);
assert_eq!(title_0.title(), "Example Title");

// `construct()`
let filedata_for_include = PlantUmlFileData::parse_from_str(data_for_include)?;
let includes = IncludesCollections::new(HashMap::from([
    ("bar/foo.puml".into(), filedata_for_include),
]));
let constructed = content.construct("bar/x.puml".into(), &includes)?;
assert_eq!(
    constructed,
    concat!(
        "@startuml\n",
        "title Example Title\n",
        "Alice -> Bob: Hello\n",
        "title Example Title Included\n",
        "Bob -> Alice: Hi\n",
        "@enduml\n",
    ),
);

// Increased the element of titles in `constructed`
let filedata = PlantUmlFileData::parse_from_str(constructed)?;
let content: &PlantUmlContent = filedata.get(0).unwrap();
let title_0 = content.titles().get(0).unwrap();
let title_1 = content.titles().get(1).unwrap();
assert!(content.titles().get(2).is_none());
assert_eq!(content.titles().len(), 2);
assert_eq!(title_0.title(), "Example Title");
assert_eq!(title_1.title(), "Example Title Included");

Implementations§

source§

impl PlantUmlContent

source

pub fn id(&self) -> Option<&str>

Returns the ID of the diagram.

source

pub fn construct( &self, base: PathBuf, includes: &IncludesCollections ) -> Result<String, Error>

Returns the string after the include process of PlantUmlContent.

  • base - A base path of self.
  • includes - A pre read PlantUmlFileData collection for the include process.
Examples
use plantuml_parser::{IncludesCollections, PlantUmlContent, PlantUmlFileData};

let data_for_include = r#"
@startuml
Bob -> Alice: Hi
@enduml
"#;

let data = r#"
@startuml
Alice -> Bob: Hello
!include foo.puml!0
@enduml
"#;

let filedata_for_include = PlantUmlFileData::parse_from_str(data_for_include)?;
let includes = IncludesCollections::new(HashMap::from([
    ("bar/foo.puml".into(), filedata_for_include),
]));

let filedata = PlantUmlFileData::parse_from_str(data)?;
let content: &PlantUmlContent = filedata.get(0).unwrap();
let constructed = content.construct("bar/x.puml".into(), &includes)?;
assert_eq!(
    constructed,
    concat!(
        "@startuml\n",
        "Alice -> Bob: Hello\n",
        "Bob -> Alice: Hi\n",
        "@enduml\n",
    ),
);

// include paths are not matched
let constructed = content.construct("bar.puml".into(), &includes)?;
assert_eq!(
    constructed,
    concat!(
        "@startuml\n",
        "Alice -> Bob: Hello\n",
        "!include foo.puml!0\n",
        "@enduml\n",
    ),
);
source

pub fn inner(&self) -> String

Returns the string in the PlantUmlContent without StartLine and EndLine.

Examples
use plantuml_parser::{PlantUmlContent, PlantUmlFileData};

let data = r#"
@startuml
Alice -> Bob: Hello
@enduml
"#;

let filedata = PlantUmlFileData::parse_from_str(data)?;
let content: &PlantUmlContent = filedata.get(0).unwrap();
assert_eq!(content.inner(), "Alice -> Bob: Hello\n");
source

pub fn includes(&self) -> &[IncludeToken]

Returns the includes in the PlantUmlContent.

source

pub fn titles(&self) -> &[TitleLine]

Returns the titles in the PlantUmlContent.

source

pub fn headers(&self) -> &[HeaderLine]

Returns the headers in the PlantUmlContent.

source

pub fn footers(&self) -> &[FooterLine]

Returns the footers in the PlantUmlContent.

Trait Implementations§

source§

impl Clone for PlantUmlContent

source§

fn clone(&self) -> PlantUmlContent

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for PlantUmlContent

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more