diff options
author | HampusM <hampus@hampusmat.com> | 2023-02-26 14:45:20 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-02-26 14:45:20 +0100 |
commit | 5ab5fafd8f3cab7f82c11e7ad89f8fefd66e911c (patch) | |
tree | 221f9a936320a894ec5706ce7a8720648e8fe497 /src/description.rs | |
parent | 2d633644a53dfe278b681a911b2eaea1230a07cc (diff) |
feat: add multiple description support
Diffstat (limited to 'src/description.rs')
-rw-r--r-- | src/description.rs | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/src/description.rs b/src/description.rs index f536b4f..ccd95b2 100644 --- a/src/description.rs +++ b/src/description.rs @@ -7,16 +7,27 @@ use crate::xml::element::{Elements, FromElements, Tagged}; #[derive(Debug, Clone, PartialEq, Eq)] pub struct Description { + for_function: Option<String>, parts: Vec<Part>, } impl Description { - /// Returns a new `ReferenceDescription`. + /// Returns a new empty `Description`. #[must_use] pub fn new() -> Self { - Self { parts: Vec::new() } + Self { + for_function: None, + parts: Vec::new(), + } + } + + /// Returns what function this description is specific for. + #[must_use] + pub fn for_function(&self) -> &Option<String> + { + &self.for_function } /// Returns the description's parts. @@ -41,6 +52,27 @@ impl FromElements for Description fn from_elements(elements: &Elements) -> Result<Self, Self::Error> { + let for_function = + elements + .get_first_tagged_with_name("title") + .and_then(|title_element| { + let title_text = + title_element.child_elements().get_first_text_element()?; + + if title_text != "Description for " { + return None; + } + + let function_element = title_element + .child_elements() + .get_first_tagged_with_name("function")?; + + function_element + .child_elements() + .get_first_text_element() + .cloned() + }); + let parts = elements .get_all_tagged_elements() .into_iter() @@ -61,7 +93,10 @@ impl FromElements for Description }) .collect::<Result<Vec<_>, Self::Error>>()?; - Ok(Description { parts }) + Ok(Description { + for_function, + parts, + }) } } |