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/lib.rs | |
| parent | 2d633644a53dfe278b681a911b2eaea1230a07cc (diff) | |
feat: add multiple description support
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 46 | 
1 files changed, 26 insertions, 20 deletions
| @@ -10,7 +10,7 @@ use std::os::unix::prelude::OsStrExt;  use include_dir::{include_dir, Dir};  use crate::description::{Description, Error as DescriptionError}; -use crate::xml::element::{Attribute, Elements, FromElements}; +use crate::xml::element::{Elements, FromElements};  use crate::xml::parser::{Error as ParserError, Parser};  pub mod description; @@ -26,17 +26,20 @@ static GL4_DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR/OpenGL-Refpages/gl4");  pub struct ReferenceEntry  {      purpose: String, -    description: Description, +    descriptions: Vec<Description>,  }  impl ReferenceEntry  {      /// Returns a new `ReferenceEntry`. -    pub fn new(purpose: &impl ToString, description: Description) -> Self +    pub fn new( +        purpose: &impl ToString, +        descriptions: impl IntoIterator<Item = Description>, +    ) -> Self      {          Self {              purpose: purpose.to_string(), -            description, +            descriptions: descriptions.into_iter().collect(),          }      } @@ -106,11 +109,11 @@ impl ReferenceEntry          &self.purpose      } -    /// Returns the reference entry description. +    /// Returns the reference entry descriptions.      #[must_use] -    pub fn description(&self) -> &Description +    pub fn descriptions(&self) -> &[Description]      { -        &self.description +        &self.descriptions      }  } @@ -140,23 +143,26 @@ impl FromElements for ReferenceEntry              .cloned()              .unwrap_or_default(); -        let description_refsect = refentry_element +        let description_elements = refentry_element              .child_elements() -            .get_first_tagged_with_name_and_attr( -                "refsect1", -                &Attribute { -                    key: "xml:id".to_string(), -                    value: b"description".to_vec(), -                }, -            ) -            .ok_or(Self::Error::MissingDescriptionRefSect)?; - -        let description = -            Description::from_elements(description_refsect.child_elements())?; +            .get_all_tagged_with_name_and_attr("refsect1", |attr| { +                attr.key == "xml:id" && attr.value.starts_with(b"description") +            }); + +        if description_elements.is_empty() { +            return Err(Self::Error::MissingDescriptionRefSect); +        } + +        let descriptions = description_elements +            .iter() +            .map(|description_element| { +                Description::from_elements(description_element.child_elements()) +            }) +            .collect::<Result<Vec<_>, _>>()?;          Ok(ReferenceEntry {              purpose, -            description, +            descriptions,          })      }  } | 
