diff --git a/src/law/mod.rs b/src/law/mod.rs index edb2540..6d740a3 100644 --- a/src/law/mod.rs +++ b/src/law/mod.rs @@ -168,7 +168,7 @@ impl LawBuilder { } /// Creates a new law builder. Adds classifier for known law texts. - pub(crate) fn new(name: &str) -> Law { + pub(crate) fn new(name: &str) -> Self { let mut classifiers = Vec::new(); let mut law_id = None; @@ -288,7 +288,7 @@ impl LawBuilder { let responsible_class = self .responsible_classifier(name) - .expect(&format!("No classifier for '{name}'")); + .unwrap_or_else(|| panic!("No classifier for '{name}'")); let mut heading: ClassifierInstance = name.into(); @@ -457,10 +457,12 @@ impl From<&str> for ClassifierInstance { } } +type ClassifierApplicable = Arc bool>; + #[derive(Clone)] pub(crate) struct Classifier { pub(crate) name: String, // Hauptstück, Theil, Abschnitt, ol - pub(crate) used_for_fn: Arc bool>, + pub(crate) used_for_fn: ClassifierApplicable, pub(crate) instances: Vec, pub(crate) child: Vec>>, pub(crate) root: bool, @@ -473,7 +475,7 @@ impl PartialEq for Classifier { } impl Classifier { - fn new(name: &str, used_for_fn: Arc bool>) -> Self { + fn new(name: &str, used_for_fn: ClassifierApplicable) -> Self { Self { name: name.into(), used_for_fn, @@ -554,7 +556,7 @@ mod tests { #[ignore] #[test] fn test_with_live_data() { - let law = LawBuilder::new("UrhG"); + let law: Law = LawBuilder::new("UrhG").into(); let path = Path::new("./data/urhg/builder.result"); let mut file = File::open(path).unwrap(); @@ -569,7 +571,7 @@ mod tests { #[ignore] #[test] fn test_stgb_with_live_data() { - let law = LawBuilder::new("StGB"); + let law: Law = LawBuilder::new("StGB").into(); let path = Path::new("./data/stgb/builder.result"); let mut file = File::open(path).unwrap(); diff --git a/src/main.rs b/src/main.rs index c352afd..a645d85 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use law::LawBuilder; +use law::{Law, LawBuilder}; mod law; mod par; @@ -6,6 +6,6 @@ mod par; fn main() { env_logger::init(); - let law = LawBuilder::new("StGB"); + let law: Law = LawBuilder::new("StGB").into(); law.to_md(); } diff --git a/src/misc.rs b/src/misc.rs index 08fe867..da10d14 100644 --- a/src/misc.rs +++ b/src/misc.rs @@ -3,6 +3,7 @@ use std::io; use time::{format_description, OffsetDateTime}; #[derive(Debug)] +#[allow(dead_code)] pub struct Error { msg: String, } diff --git a/src/risparser/overview.rs b/src/risparser/overview.rs index 2b1d557..621faee 100644 --- a/src/risparser/overview.rs +++ b/src/risparser/overview.rs @@ -7,6 +7,11 @@ use crate::misc::{current_date, Error}; use super::parser::OgdSearchResult; +/// # Parameters +/// - `law_id`: Id from RIS of a law +/// +/// # Returns +/// Error, or a list of Xml file links of the given law text pub fn parse(law_id: usize) -> Result, Error> { let mut page = 1; let mut skip = true; @@ -34,6 +39,7 @@ struct Overview { ogd_search_result: OgdSearchResult, } +//TODO: Remove, as we don't want to test internals? #[cfg(test)] pub(crate) fn parse_from_str_test( content: &str, diff --git a/src/risparser/parser.rs b/src/risparser/parser.rs index dbb84fe..7862d3b 100644 --- a/src/risparser/parser.rs +++ b/src/risparser/parser.rs @@ -12,6 +12,7 @@ where #[derive(Deserialize)] #[serde(rename_all = "PascalCase")] +#[allow(dead_code)] pub(crate) struct OgdSearchResult { ogd_document_results: OgdDocumentResults, } @@ -49,12 +50,14 @@ impl OgdSearchResult { #[derive(Deserialize)] #[serde(rename_all = "PascalCase")] +#[allow(dead_code)] pub(crate) struct OgdDocumentResults { hits: Hits, ogd_document_reference: Vec, } #[derive(Deserialize)] +#[allow(dead_code)] pub(crate) struct Hits { #[serde( rename = "@pageNumber", @@ -68,12 +71,14 @@ pub(crate) struct Hits { } #[derive(Deserialize)] +#[allow(dead_code)] #[serde(rename_all = "PascalCase")] pub(crate) struct OgdDocumentReference { data: Data, } #[derive(Deserialize)] +#[allow(dead_code)] pub(crate) struct Data { #[serde(rename = "Metadaten")] metadata: Metadata, @@ -82,6 +87,7 @@ pub(crate) struct Data { } #[derive(Deserialize)] +#[allow(dead_code)] pub(crate) struct Metadata { #[serde(rename = "Technisch")] technical: TechnicalMetadata, @@ -94,6 +100,7 @@ pub(crate) struct Metadata { } #[derive(Deserialize)] +#[allow(dead_code)] #[serde(rename_all = "PascalCase")] pub(crate) struct TechnicalMetadata { #[serde(rename = "ID")] @@ -108,6 +115,7 @@ pub(crate) struct TechnicalMetadata { } #[derive(Deserialize)] +#[allow(dead_code)] pub(crate) struct ImportTimestamp { #[serde(rename = "@xsi:nil")] xsi_nil: String, //TODO: switch to bool @@ -117,6 +125,7 @@ pub(crate) struct ImportTimestamp { } #[derive(Deserialize)] +#[allow(dead_code)] pub(crate) struct GeneralMetadata { #[serde(rename = "Geaendert")] changed: String, //TODO: switch to YYYY-MM-DD string @@ -126,6 +135,7 @@ pub(crate) struct GeneralMetadata { } #[derive(Deserialize)] +#[allow(dead_code)] #[serde(rename_all = "PascalCase")] pub(crate) struct FedMetadata { #[serde(rename = "Kurztitel")] @@ -140,6 +150,7 @@ pub(crate) struct FedMetadata { } #[derive(Deserialize)] +#[allow(dead_code)] #[serde(rename_all = "PascalCase")] pub(crate) struct BrKons { kundmachungsorgan: String, @@ -164,12 +175,14 @@ pub(crate) struct BrKons { } #[derive(Deserialize)] +#[allow(dead_code)] #[serde(rename_all = "PascalCase")] pub(crate) struct DocumentList { content_reference: ContentReference, } #[derive(Deserialize)] +#[allow(dead_code)] #[serde(rename_all = "PascalCase")] pub(crate) struct ContentReference { content_type: String, @@ -178,12 +191,14 @@ pub(crate) struct ContentReference { } #[derive(Deserialize)] +#[allow(dead_code)] #[serde(rename_all = "PascalCase")] pub(crate) struct ContentUrl { content_url: Vec, } #[derive(Deserialize)] +#[allow(dead_code)] #[serde(rename_all = "PascalCase")] pub(crate) struct ContentUrlItem { data_type: String, @@ -213,7 +228,9 @@ mod tests { buf_reader.lines().collect() } + //TODO: remove, as we don't want to test interal stuff? #[derive(Deserialize)] + #[allow(dead_code)] #[serde(rename_all = "PascalCase")] pub(crate) struct Wrapper { ogd_search_result: OgdSearchResult,