Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ unic-langid = { version = "0.9.6", features = ["serde"] }
unicode-segmentation = "1.6.0"
unscanny = "0.1.0"
url = { version = "2.4", features = ["serde"] }
biblatex = { version = "0.11.0", features = [
"unic-langid",
], optional = true }
biblatex = { version = "0.11.0", features = ["unic-langid"], optional = true }
ciborium = { version = "0.2.1", optional = true }
clap = { version = "4", optional = true, features = ["cargo"] }
strum = { version = "0.26", features = ["derive"], optional = true }
Expand Down
18 changes: 13 additions & 5 deletions src/csl/elem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use citationberg::{
Display, FontStyle, FontVariant, FontWeight, TextDecoration, VerticalAlign,
};

use crate::types::Person;

/// A container for elements with useful methods.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Elem {
Expand Down Expand Up @@ -118,10 +120,10 @@ pub(super) fn simplify_children(children: ElemChildren) -> ElemChildren {
}

/// Which CSL construct created an element.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ElemMeta {
/// The element is the output of `cs:names`.
Names,
/// The element is the output of `cs:names` with the names of the corresponding variables for this elem.
Names(Vec<(Vec<Person>, NameVariable)>),
/// The element is the output of `cs:date`.
Date,
/// The element is the output of `cs:text`.
Expand Down Expand Up @@ -164,8 +166,14 @@ impl ElemChildren {

/// Retrieve a reference to the first child with a matching meta by
/// DFS.
pub fn find_meta(&self, meta: ElemMeta) -> Option<&Elem> {
self.find_elem_by(&|e| e.meta == Some(meta))
pub fn find_meta(&self, meta: &ElemMeta) -> Option<&Elem> {
self.find_elem_by(&|e| e.meta.as_ref() == Some(meta))
}

/// Retrieve a reference to the first child with a names meta by
/// DFS.
pub fn find_names(&self) -> Option<&Elem> {
self.find_elem_by(&|e| matches!(e.meta, Some(ElemMeta::Names(_))))
}

/// Retrieve a mutable reference to the first child matching the predicate
Expand Down
Loading