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
impl PlantUmlContent
Sourcepub fn construct(
&self,
base: PathBuf,
includes: &IncludesCollections,
) -> Result<String, Error>
pub fn construct( &self, base: PathBuf, includes: &IncludesCollections, ) -> Result<String, Error>
Returns the string after the include process of PlantUmlContent.
base- A base path ofself.includes- A pre readPlantUmlFileDatacollection 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",
),
);Sourcepub fn inner(&self) -> String
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");Sourcepub fn blocks(&self) -> &[PlantUmlBlock]
pub fn blocks(&self) -> &[PlantUmlBlock]
Returns the list of PlantUmlBlock in the PlantUmlContent.
Sourcepub fn includes(&self) -> &[IncludeToken]
pub fn includes(&self) -> &[IncludeToken]
Returns the includes in the PlantUmlContent.
Sourcepub fn titles(&self) -> &[TitleLine]
pub fn titles(&self) -> &[TitleLine]
Returns the titles in the PlantUmlContent.
Sourcepub fn headers(&self) -> &[HeaderLine]
pub fn headers(&self) -> &[HeaderLine]
Returns the headers in the PlantUmlContent.
Returns the footers in the PlantUmlContent.
Trait Implementations§
Source§impl Clone for PlantUmlContent
impl Clone for PlantUmlContent
Source§fn clone(&self) -> PlantUmlContent
fn clone(&self) -> PlantUmlContent
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for PlantUmlContent
impl RefUnwindSafe for PlantUmlContent
impl Send for PlantUmlContent
impl Sync for PlantUmlContent
impl Unpin for PlantUmlContent
impl UnwindSafe for PlantUmlContent
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more