From e6bda9c1131ae9d54d65b81e2674179803644cd3 Mon Sep 17 00:00:00 2001 From: Martin Haug Date: Mon, 16 Oct 2023 18:49:46 +0200 Subject: [PATCH] Name change --- src/lib.rs | 50 ++++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 45aa8be..9c1c2a5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -127,7 +127,7 @@ struct RawStyle { pub bibliography: Option, /// The style's settings. Must be present in dependent styles. #[serde(flatten)] - pub independant_settings: Option, + pub independent_settings: Option, /// Reusable formatting rules. #[serde(rename = "macro", default)] pub macros: Vec, @@ -137,13 +137,6 @@ struct RawStyle { } impl RawStyle { - /// Create a style from an XML file. - pub fn from_xml(xml: &str) -> Result { - let de = &mut deserializer(xml); - let style = RawStyle::deserialize(de)?; - Ok(style) - } - /// Retrieve the link to the parent style for dependent styles. pub fn parent_link(&self) -> Option<&InfoLink> { self.info @@ -151,11 +144,6 @@ impl RawStyle { .iter() .find(|link| link.rel == InfoLinkRel::IndependentParent) } - - /// Check if the style is dependent. - pub fn is_dependent(&self) -> bool { - self.independant_settings.is_none() && self.citation.is_none() - } } /// An independent CSL style. @@ -172,13 +160,21 @@ pub struct IndependentStyle { /// How bibliographies are displayed. pub bibliography: Option, /// The style's settings. Must be present in dependent styles. - pub independant_settings: IndependentStyleSettings, + pub settings: IndependentStyleSettings, /// Reusable formatting rules. pub macros: Vec, /// Override localized strings. pub locale: Vec, } +impl IndependentStyle { + /// Create a style from an XML file. + pub fn from_xml(xml: &str) -> Result { + let de = &mut deserializer(xml); + IndependentStyle::deserialize(de) + } +} + impl<'de> Deserialize<'de> for IndependentStyle { fn deserialize>( deserializer: D, @@ -209,6 +205,14 @@ pub struct DependentStyle { pub parent_link: InfoLink, } +impl DependentStyle { + /// Create a style from an XML file. + pub fn from_xml(xml: &str) -> Result { + let de = &mut deserializer(xml); + DependentStyle::deserialize(de) + } +} + impl<'de> Deserialize<'de> for DependentStyle { fn deserialize>( deserializer: D, @@ -235,6 +239,14 @@ pub enum Style { Dependent(DependentStyle), } +impl Style { + /// Create a style from an XML file. + pub fn from_xml(xml: &str) -> Result { + let de = &mut deserializer(xml); + Style::deserialize(de) + } +} + impl<'de> Deserialize<'de> for Style { fn deserialize>( deserializer: D, @@ -250,14 +262,14 @@ impl TryFrom for Style { fn try_from(value: RawStyle) -> Result { let has_bibliography = value.bibliography.is_some(); if let Some(citation) = value.citation { - if let Some(settings) = value.independant_settings { + if let Some(settings) = value.independent_settings { Ok(Self::Independent(IndependentStyle { info: value.info, default_locale: value.default_locale, version: value.version, citation, bibliography: value.bibliography, - independant_settings: settings, + settings, macros: value.macros, locale: value.locale, })) @@ -301,12 +313,6 @@ impl fmt::Display for StyleValidationError { } } -/// Deserialize a CSL style from an XML string. -pub fn deserialize_csl_str(s: &str) -> Result { - let de = &mut deserializer(s); - Style::deserialize(de) -} - fn deserializer(xml: &str) -> Deserializer> { let mut style_deserializer = Deserializer::from_str(xml); style_deserializer.event_buffer_size(EVENT_BUFFER_SIZE);