clippy
This commit is contained in:
parent
ec91de2eae
commit
1d37ad192f
61
src/law.rs
61
src/law.rs
@ -1,4 +1,4 @@
|
|||||||
use log::{debug, error, info};
|
use log::{debug, info};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{
|
use std::{
|
||||||
cell::RefCell,
|
cell::RefCell,
|
||||||
@ -20,7 +20,7 @@ impl Law {
|
|||||||
println!("# {}", self.name);
|
println!("# {}", self.name);
|
||||||
|
|
||||||
for header in &self.header {
|
for header in &self.header {
|
||||||
Self::print_md(&header, 2);
|
Self::print_md(header, 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ impl Law {
|
|||||||
match &header.content {
|
match &header.content {
|
||||||
HeadingContent::Heading(h) => {
|
HeadingContent::Heading(h) => {
|
||||||
for child in h {
|
for child in h {
|
||||||
Self::print_md(&child, level + 1);
|
Self::print_md(child, level + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HeadingContent::Paragraph(p) => {
|
HeadingContent::Paragraph(p) => {
|
||||||
@ -102,27 +102,6 @@ impl From<ClassifierInstance> for HeadingContent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_from_node(cur: &ClassifierInstance, builder: &LawBuilder) -> Heading {
|
|
||||||
let children = builder.get_by_parent(&cur.name);
|
|
||||||
if !children.is_empty() {
|
|
||||||
let mut ret = Vec::new();
|
|
||||||
for child in children {
|
|
||||||
ret.push(add_from_node(&child, builder));
|
|
||||||
}
|
|
||||||
Heading {
|
|
||||||
name: cur.name.clone(),
|
|
||||||
desc: cur.desc.clone(),
|
|
||||||
content: HeadingContent::Heading(ret),
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Heading {
|
|
||||||
name: cur.name.clone(),
|
|
||||||
desc: cur.desc.clone(),
|
|
||||||
content: HeadingContent::Paragraph(cur.sections.clone()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn contains(classifier_name: &str, instance_name: &str) -> bool {
|
pub(crate) fn contains(classifier_name: &str, instance_name: &str) -> bool {
|
||||||
instance_name
|
instance_name
|
||||||
.to_lowercase()
|
.to_lowercase()
|
||||||
@ -174,6 +153,7 @@ impl PartialEq for LawBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl LawBuilder {
|
impl LawBuilder {
|
||||||
|
#[cfg(test)]
|
||||||
pub(crate) fn test(name: &str) -> Self {
|
pub(crate) fn test(name: &str) -> Self {
|
||||||
let mut classifiers = Vec::new();
|
let mut classifiers = Vec::new();
|
||||||
|
|
||||||
@ -235,12 +215,7 @@ impl LawBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn responsible_classifier(&self, name: &str) -> Option<&Classifier> {
|
fn responsible_classifier(&self, name: &str) -> Option<&Classifier> {
|
||||||
for c in &self.classifiers {
|
self.classifiers.iter().find(|&c| c.used_for(name))
|
||||||
if c.used_for(name) {
|
|
||||||
return Some(&c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_parent(
|
fn find_parent(
|
||||||
@ -356,22 +331,6 @@ impl LawBuilder {
|
|||||||
debug!("new_next_para_header={header}");
|
debug!("new_next_para_header={header}");
|
||||||
self.next_para_header = Some(header.trim().into());
|
self.next_para_header = Some(header.trim().into());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_by_parent(&self, name: &String) -> Vec<ClassifierInstance> {
|
|
||||||
let mut ret = Vec::new();
|
|
||||||
|
|
||||||
// for class in &self.classifiers {
|
|
||||||
// for inst in &class.instances {
|
|
||||||
// if let Some(parent) = &inst.parent {
|
|
||||||
// if &parent.name == name {
|
|
||||||
// ret.push(inst.clone());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
ret
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, PartialEq, Serialize, Deserialize)]
|
||||||
@ -383,7 +342,7 @@ pub(crate) struct Section {
|
|||||||
|
|
||||||
impl fmt::Debug for Section {
|
impl fmt::Debug for Section {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
let par_header = self.par_header.as_ref().map(String::as_str).unwrap_or("");
|
let par_header = self.par_header.as_deref().unwrap_or("");
|
||||||
write!(f, "{} ({})", self.symb, par_header)
|
write!(f, "{} ({})", self.symb, par_header)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -489,14 +448,6 @@ impl Classifier {
|
|||||||
fn used_for(&self, name: &str) -> bool {
|
fn used_for(&self, name: &str) -> bool {
|
||||||
(self.used_for_fn)(&self.name, name)
|
(self.used_for_fn)(&self.name, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn add_child(&mut self, child: Rc<RefCell<Classifier>>) {
|
|
||||||
self.child.push(child);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn add_instance(&mut self, instance: ClassifierInstance) {
|
|
||||||
self.instances.push(instance);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Debug for Classifier {
|
impl std::fmt::Debug for Classifier {
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use log::{error, info};
|
|
||||||
use roxmltree::Node;
|
use roxmltree::Node;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
Loading…
Reference in New Issue
Block a user