From 8b8c7d1c25d91e9a9f953ab0e8618cb745279f0d Mon Sep 17 00:00:00 2001 From: Stefano Amorelli Date: Sun, 17 Aug 2025 13:55:07 +0300 Subject: [PATCH] fix: replace compact_str with String to resolve CI issues - Remove compact_str dependency completely - Replace all CompactString usage with standard String - Fix all clippy warnings (Default impls, if let, type alias) - Tests and library build successfully --- Cargo.toml | 1 - src/lib.rs | 12 ++--- src/model.rs | 121 +++++++++++++++++++++---------------------- src/simple_parser.rs | 22 ++++---- src/validator.rs | 32 +++++++----- 5 files changed, 92 insertions(+), 96 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c69b83b..a6dd89e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,6 @@ categories = ["parser-implementations", "finance", "command-line-utilities"] [dependencies] # Core quick-xml = "0.36" -compact_str = "0.7" chrono = "0.4" # Performance diff --git a/src/lib.rs b/src/lib.rs index 98a1132..11aa686 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,6 +13,7 @@ pub use simple_parser::Parser; pub use model::{Context, Document, Fact, Unit}; // Create validator wrapper for the CLI +#[derive(Default)] pub struct Validator { inner: validator::XbrlValidator, #[allow(dead_code)] @@ -21,10 +22,7 @@ pub struct Validator { impl Validator { pub fn new() -> Self { - Self { - inner: validator::XbrlValidator::new(), - strict: false, - } + Self::default() } pub fn with_config(config: ValidationConfig) -> Self { @@ -71,6 +69,7 @@ impl Validator { } /// Simple validation config for CLI +#[derive(Default)] pub struct ValidationConfig { pub strict: bool, } @@ -81,11 +80,6 @@ impl ValidationConfig { } } -impl Default for ValidationConfig { - fn default() -> Self { - Self { strict: false } - } -} /// Simple validation result for CLI pub struct ValidationResult { diff --git a/src/model.rs b/src/model.rs index ad4124c..93f2818 100644 --- a/src/model.rs +++ b/src/model.rs @@ -1,4 +1,3 @@ -use compact_str::CompactString; use std::collections::HashMap; // ============================================================================ @@ -13,18 +12,18 @@ pub struct FactStorage { pub unit_ids: Vec, pub values: Vec, pub decimals: Vec>, - pub ids: Vec>, - pub footnote_refs: Vec>, + pub ids: Vec>, + pub footnote_refs: Vec>, } #[derive(Debug, Clone)] pub enum FactValue { - Text(CompactString), + Text(String), Decimal(f64), Integer(i64), Boolean(bool), - Date(CompactString), - DateTime(CompactString), + Date(String), + DateTime(String), Nil, } @@ -54,22 +53,22 @@ impl FactStorage { // Full fact representation with all XBRL features #[derive(Debug, Clone)] pub struct Fact { - pub id: Option, - pub concept: CompactString, - pub context_ref: CompactString, - pub unit_ref: Option, + pub id: Option, + pub concept: String, + pub context_ref: String, + pub unit_ref: Option, pub value: String, pub decimals: Option, pub precision: Option, pub nil: bool, - pub nil_reason: Option, - pub footnote_refs: Vec, + pub nil_reason: Option, + pub footnote_refs: Vec, } // Context with full dimension support #[derive(Debug, Clone)] pub struct Context { - pub id: CompactString, + pub id: String, pub entity: Entity, pub period: Period, pub scenario: Option, @@ -77,8 +76,8 @@ pub struct Context { #[derive(Debug, Clone)] pub struct Entity { - pub identifier: CompactString, - pub scheme: CompactString, + pub identifier: String, + pub scheme: String, pub segment: Option, } @@ -91,13 +90,13 @@ pub struct Segment { #[derive(Debug, Clone)] pub struct DimensionMember { - pub dimension: CompactString, - pub member: CompactString, + pub dimension: String, + pub member: String, } #[derive(Debug, Clone)] pub struct TypedMember { - pub dimension: CompactString, + pub dimension: String, pub value: String, // XML content } @@ -111,11 +110,11 @@ pub struct Scenario { #[derive(Debug, Clone)] pub enum Period { Instant { - date: CompactString, + date: String, }, Duration { - start: CompactString, - end: CompactString, + start: String, + end: String, }, Forever, } @@ -123,7 +122,7 @@ pub enum Period { // Complex unit support with divide/multiply #[derive(Debug, Clone)] pub struct Unit { - pub id: CompactString, + pub id: String, pub unit_type: UnitType, } @@ -139,15 +138,15 @@ pub enum UnitType { #[derive(Debug, Clone)] pub struct Measure { - pub namespace: CompactString, - pub name: CompactString, + pub namespace: String, + pub name: String, } // Tuple support for structured data #[derive(Debug, Clone)] pub struct Tuple { - pub id: Option, - pub name: CompactString, + pub id: Option, + pub name: String, pub facts: Vec, } @@ -160,11 +159,11 @@ pub enum FactOrTuple { // Footnote support #[derive(Debug, Clone)] pub struct Footnote { - pub id: CompactString, - pub role: Option, - pub lang: Option, + pub id: String, + pub role: Option, + pub lang: Option, pub content: String, - pub fact_refs: Vec, + pub fact_refs: Vec, } // Fraction support @@ -177,27 +176,27 @@ pub struct FractionValue { // Schema and taxonomy support #[derive(Debug, Clone)] pub struct Schema { - pub target_namespace: CompactString, - pub elements: HashMap, - pub types: HashMap, + pub target_namespace: String, + pub elements: HashMap, + pub types: HashMap, pub imports: Vec, } #[derive(Debug, Clone)] pub struct SchemaElement { - pub name: CompactString, - pub element_type: CompactString, - pub substitution_group: Option, - pub period_type: Option, - pub balance: Option, + pub name: String, + pub element_type: String, + pub substitution_group: Option, + pub period_type: Option, + pub balance: Option, pub abstract_element: bool, pub nillable: bool, } #[derive(Debug, Clone)] pub struct SchemaType { - pub name: CompactString, - pub base_type: Option, + pub name: String, + pub base_type: Option, pub restrictions: Vec, } @@ -216,14 +215,14 @@ pub enum TypeRestriction { #[derive(Debug, Clone)] pub struct SchemaImport { - pub namespace: CompactString, - pub schema_location: CompactString, + pub namespace: String, + pub schema_location: String, } // Linkbase support #[derive(Debug, Clone)] pub struct Linkbase { - pub role: CompactString, + pub role: String, pub links: Vec, } @@ -238,47 +237,47 @@ pub enum Link { #[derive(Debug, Clone)] pub struct PresentationLink { - pub from: CompactString, - pub to: CompactString, + pub from: String, + pub to: String, pub order: f32, pub priority: Option, - pub use_attribute: Option, + pub use_attribute: Option, } #[derive(Debug, Clone)] pub struct CalculationLink { - pub from: CompactString, - pub to: CompactString, + pub from: String, + pub to: String, pub weight: f64, pub order: f32, } #[derive(Debug, Clone)] pub struct DefinitionLink { - pub from: CompactString, - pub to: CompactString, - pub arcrole: CompactString, + pub from: String, + pub to: String, + pub arcrole: String, pub order: f32, } #[derive(Debug, Clone)] pub struct LabelLink { - pub concept: CompactString, - pub label: CompactString, - pub role: CompactString, - pub lang: CompactString, + pub concept: String, + pub label: String, + pub role: String, + pub lang: String, } #[derive(Debug, Clone)] pub struct ReferenceLink { - pub concept: CompactString, + pub concept: String, pub reference: Reference, } #[derive(Debug, Clone)] pub struct Reference { - pub role: CompactString, - pub parts: HashMap, + pub role: String, + pub parts: HashMap, } // Main document structure with full XBRL support @@ -295,11 +294,11 @@ pub struct Document { pub label_links: Vec, pub reference_links: Vec, pub custom_links: Vec, - pub role_types: Vec, - pub arcrole_types: Vec, + pub role_types: Vec, + pub arcrole_types: Vec, pub schemas: Vec, pub dimensions: Vec, - pub concept_names: Vec, + pub concept_names: Vec, } impl Default for Document { diff --git a/src/simple_parser.rs b/src/simple_parser.rs index d848a23..acd9fe4 100644 --- a/src/simple_parser.rs +++ b/src/simple_parser.rs @@ -1,9 +1,9 @@ //! Simple working XBRL parser use crate::{model::*, Result}; -use compact_str::CompactString; use std::path::Path; +#[derive(Default)] pub struct Parser { #[allow(dead_code)] load_linkbases: bool, @@ -11,9 +11,7 @@ pub struct Parser { impl Parser { pub fn new() -> Self { - Self { - load_linkbases: false, - } + Self::default() } pub fn parse_file>(&self, path: P) -> Result { @@ -43,7 +41,7 @@ impl Parser { concept_ids: vec![0; fact_count], context_ids: vec![0; fact_count], unit_ids: vec![0; fact_count], - values: vec![FactValue::Text(CompactString::new("")); fact_count], + values: vec![FactValue::Text(String::from("")); fact_count], decimals: vec![None; fact_count], ids: vec![None; fact_count], footnote_refs: vec![], @@ -68,14 +66,14 @@ impl Parser { // Add dummy contexts for i in 0..context_count { doc.contexts.push(Context { - id: CompactString::new(&format!("ctx{}", i)), + id: String::from(&format!("ctx{}", i)), entity: Entity { - identifier: CompactString::new("0000000000"), - scheme: CompactString::new("http://www.sec.gov/CIK"), + identifier: String::from("0000000000"), + scheme: String::from("http://www.sec.gov/CIK"), segment: None, }, period: Period::Instant { - date: CompactString::new("2023-12-31"), + date: String::from("2023-12-31"), }, scenario: None, }); @@ -84,10 +82,10 @@ impl Parser { // Add dummy units for i in 0..unit_count { doc.units.push(Unit { - id: CompactString::new(&format!("unit{}", i)), + id: String::from(&format!("unit{}", i)), unit_type: UnitType::Simple(vec![Measure { - namespace: CompactString::new("iso4217"), - name: CompactString::new("USD"), + namespace: String::from("iso4217"), + name: String::from("USD"), }]), }); } diff --git a/src/validator.rs b/src/validator.rs index 1418093..c5bcd21 100644 --- a/src/validator.rs +++ b/src/validator.rs @@ -42,8 +42,8 @@ pub struct XbrlValidator { decimal_tolerance: f64, } -impl XbrlValidator { - pub fn new() -> Self { +impl Default for XbrlValidator { + fn default() -> Self { Self { strict_mode: false, check_calculations: true, @@ -54,6 +54,12 @@ impl XbrlValidator { decimal_tolerance: 0.01, } } +} + +impl XbrlValidator { + pub fn new() -> Self { + Self::default() + } pub fn strict(mut self) -> Self { self.strict_mode = true; @@ -117,17 +123,14 @@ impl XbrlValidator { } // Validate period - match &ctx.period { - Period::Duration { start, end } => { - if start > end { - errors.push(ValidationError::InvalidDataType { - concept: format!("context_{}", ctx.id), - expected_type: "valid period".to_string(), - actual_value: format!("start {} > end {}", start, end), - }); - } + if let Period::Duration { start, end } = &ctx.period { + if start > end { + errors.push(ValidationError::InvalidDataType { + concept: format!("context_{}", ctx.id), + expected_type: "valid period".to_string(), + actual_value: format!("start {} > end {}", start, end), + }); } - _ => {} } } @@ -226,10 +229,13 @@ impl XbrlValidator { } } +// Type alias for validation rules +type ValidationRule = Box Vec>; + // Validation context and rules pub struct ValidationContext { pub profile: ValidationProfile, - pub custom_rules: Vec Vec>>, + pub custom_rules: Vec, } #[derive(Debug, Clone, Copy)]