summaryrefslogtreecommitdiff
path: root/src/description.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/description.rs')
-rw-r--r--src/description.rs41
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,
+ })
}
}