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
This commit is contained in:
Stefano Amorelli
2025-08-17 13:55:07 +03:00
parent bb61efca48
commit 8b8c7d1c25
5 changed files with 92 additions and 96 deletions

View File

@@ -12,7 +12,6 @@ categories = ["parser-implementations", "finance", "command-line-utilities"]
[dependencies] [dependencies]
# Core # Core
quick-xml = "0.36" quick-xml = "0.36"
compact_str = "0.7"
chrono = "0.4" chrono = "0.4"
# Performance # Performance

View File

@@ -13,6 +13,7 @@ pub use simple_parser::Parser;
pub use model::{Context, Document, Fact, Unit}; pub use model::{Context, Document, Fact, Unit};
// Create validator wrapper for the CLI // Create validator wrapper for the CLI
#[derive(Default)]
pub struct Validator { pub struct Validator {
inner: validator::XbrlValidator, inner: validator::XbrlValidator,
#[allow(dead_code)] #[allow(dead_code)]
@@ -21,10 +22,7 @@ pub struct Validator {
impl Validator { impl Validator {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self::default()
inner: validator::XbrlValidator::new(),
strict: false,
}
} }
pub fn with_config(config: ValidationConfig) -> Self { pub fn with_config(config: ValidationConfig) -> Self {
@@ -71,6 +69,7 @@ impl Validator {
} }
/// Simple validation config for CLI /// Simple validation config for CLI
#[derive(Default)]
pub struct ValidationConfig { pub struct ValidationConfig {
pub strict: bool, pub strict: bool,
} }
@@ -81,11 +80,6 @@ impl ValidationConfig {
} }
} }
impl Default for ValidationConfig {
fn default() -> Self {
Self { strict: false }
}
}
/// Simple validation result for CLI /// Simple validation result for CLI
pub struct ValidationResult { pub struct ValidationResult {

View File

@@ -1,4 +1,3 @@
use compact_str::CompactString;
use std::collections::HashMap; use std::collections::HashMap;
// ============================================================================ // ============================================================================
@@ -13,18 +12,18 @@ pub struct FactStorage {
pub unit_ids: Vec<u16>, pub unit_ids: Vec<u16>,
pub values: Vec<FactValue>, pub values: Vec<FactValue>,
pub decimals: Vec<Option<i8>>, pub decimals: Vec<Option<i8>>,
pub ids: Vec<Option<CompactString>>, pub ids: Vec<Option<String>>,
pub footnote_refs: Vec<Vec<CompactString>>, pub footnote_refs: Vec<Vec<String>>,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum FactValue { pub enum FactValue {
Text(CompactString), Text(String),
Decimal(f64), Decimal(f64),
Integer(i64), Integer(i64),
Boolean(bool), Boolean(bool),
Date(CompactString), Date(String),
DateTime(CompactString), DateTime(String),
Nil, Nil,
} }
@@ -54,22 +53,22 @@ impl FactStorage {
// Full fact representation with all XBRL features // Full fact representation with all XBRL features
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Fact { pub struct Fact {
pub id: Option<CompactString>, pub id: Option<String>,
pub concept: CompactString, pub concept: String,
pub context_ref: CompactString, pub context_ref: String,
pub unit_ref: Option<CompactString>, pub unit_ref: Option<String>,
pub value: String, pub value: String,
pub decimals: Option<i8>, pub decimals: Option<i8>,
pub precision: Option<u8>, pub precision: Option<u8>,
pub nil: bool, pub nil: bool,
pub nil_reason: Option<CompactString>, pub nil_reason: Option<String>,
pub footnote_refs: Vec<CompactString>, pub footnote_refs: Vec<String>,
} }
// Context with full dimension support // Context with full dimension support
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Context { pub struct Context {
pub id: CompactString, pub id: String,
pub entity: Entity, pub entity: Entity,
pub period: Period, pub period: Period,
pub scenario: Option<Scenario>, pub scenario: Option<Scenario>,
@@ -77,8 +76,8 @@ pub struct Context {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Entity { pub struct Entity {
pub identifier: CompactString, pub identifier: String,
pub scheme: CompactString, pub scheme: String,
pub segment: Option<Segment>, pub segment: Option<Segment>,
} }
@@ -91,13 +90,13 @@ pub struct Segment {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct DimensionMember { pub struct DimensionMember {
pub dimension: CompactString, pub dimension: String,
pub member: CompactString, pub member: String,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct TypedMember { pub struct TypedMember {
pub dimension: CompactString, pub dimension: String,
pub value: String, // XML content pub value: String, // XML content
} }
@@ -111,11 +110,11 @@ pub struct Scenario {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum Period { pub enum Period {
Instant { Instant {
date: CompactString, date: String,
}, },
Duration { Duration {
start: CompactString, start: String,
end: CompactString, end: String,
}, },
Forever, Forever,
} }
@@ -123,7 +122,7 @@ pub enum Period {
// Complex unit support with divide/multiply // Complex unit support with divide/multiply
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Unit { pub struct Unit {
pub id: CompactString, pub id: String,
pub unit_type: UnitType, pub unit_type: UnitType,
} }
@@ -139,15 +138,15 @@ pub enum UnitType {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Measure { pub struct Measure {
pub namespace: CompactString, pub namespace: String,
pub name: CompactString, pub name: String,
} }
// Tuple support for structured data // Tuple support for structured data
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Tuple { pub struct Tuple {
pub id: Option<CompactString>, pub id: Option<String>,
pub name: CompactString, pub name: String,
pub facts: Vec<FactOrTuple>, pub facts: Vec<FactOrTuple>,
} }
@@ -160,11 +159,11 @@ pub enum FactOrTuple {
// Footnote support // Footnote support
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Footnote { pub struct Footnote {
pub id: CompactString, pub id: String,
pub role: Option<CompactString>, pub role: Option<String>,
pub lang: Option<CompactString>, pub lang: Option<String>,
pub content: String, pub content: String,
pub fact_refs: Vec<CompactString>, pub fact_refs: Vec<String>,
} }
// Fraction support // Fraction support
@@ -177,27 +176,27 @@ pub struct FractionValue {
// Schema and taxonomy support // Schema and taxonomy support
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Schema { pub struct Schema {
pub target_namespace: CompactString, pub target_namespace: String,
pub elements: HashMap<CompactString, SchemaElement>, pub elements: HashMap<String, SchemaElement>,
pub types: HashMap<CompactString, SchemaType>, pub types: HashMap<String, SchemaType>,
pub imports: Vec<SchemaImport>, pub imports: Vec<SchemaImport>,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct SchemaElement { pub struct SchemaElement {
pub name: CompactString, pub name: String,
pub element_type: CompactString, pub element_type: String,
pub substitution_group: Option<CompactString>, pub substitution_group: Option<String>,
pub period_type: Option<CompactString>, pub period_type: Option<String>,
pub balance: Option<CompactString>, pub balance: Option<String>,
pub abstract_element: bool, pub abstract_element: bool,
pub nillable: bool, pub nillable: bool,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct SchemaType { pub struct SchemaType {
pub name: CompactString, pub name: String,
pub base_type: Option<CompactString>, pub base_type: Option<String>,
pub restrictions: Vec<TypeRestriction>, pub restrictions: Vec<TypeRestriction>,
} }
@@ -216,14 +215,14 @@ pub enum TypeRestriction {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct SchemaImport { pub struct SchemaImport {
pub namespace: CompactString, pub namespace: String,
pub schema_location: CompactString, pub schema_location: String,
} }
// Linkbase support // Linkbase support
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Linkbase { pub struct Linkbase {
pub role: CompactString, pub role: String,
pub links: Vec<Link>, pub links: Vec<Link>,
} }
@@ -238,47 +237,47 @@ pub enum Link {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct PresentationLink { pub struct PresentationLink {
pub from: CompactString, pub from: String,
pub to: CompactString, pub to: String,
pub order: f32, pub order: f32,
pub priority: Option<i32>, pub priority: Option<i32>,
pub use_attribute: Option<CompactString>, pub use_attribute: Option<String>,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct CalculationLink { pub struct CalculationLink {
pub from: CompactString, pub from: String,
pub to: CompactString, pub to: String,
pub weight: f64, pub weight: f64,
pub order: f32, pub order: f32,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct DefinitionLink { pub struct DefinitionLink {
pub from: CompactString, pub from: String,
pub to: CompactString, pub to: String,
pub arcrole: CompactString, pub arcrole: String,
pub order: f32, pub order: f32,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct LabelLink { pub struct LabelLink {
pub concept: CompactString, pub concept: String,
pub label: CompactString, pub label: String,
pub role: CompactString, pub role: String,
pub lang: CompactString, pub lang: String,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct ReferenceLink { pub struct ReferenceLink {
pub concept: CompactString, pub concept: String,
pub reference: Reference, pub reference: Reference,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Reference { pub struct Reference {
pub role: CompactString, pub role: String,
pub parts: HashMap<CompactString, String>, pub parts: HashMap<String, String>,
} }
// Main document structure with full XBRL support // Main document structure with full XBRL support
@@ -295,11 +294,11 @@ pub struct Document {
pub label_links: Vec<LabelLink>, pub label_links: Vec<LabelLink>,
pub reference_links: Vec<ReferenceLink>, pub reference_links: Vec<ReferenceLink>,
pub custom_links: Vec<Link>, pub custom_links: Vec<Link>,
pub role_types: Vec<CompactString>, pub role_types: Vec<String>,
pub arcrole_types: Vec<CompactString>, pub arcrole_types: Vec<String>,
pub schemas: Vec<Schema>, pub schemas: Vec<Schema>,
pub dimensions: Vec<DimensionMember>, pub dimensions: Vec<DimensionMember>,
pub concept_names: Vec<CompactString>, pub concept_names: Vec<String>,
} }
impl Default for Document { impl Default for Document {

View File

@@ -1,9 +1,9 @@
//! Simple working XBRL parser //! Simple working XBRL parser
use crate::{model::*, Result}; use crate::{model::*, Result};
use compact_str::CompactString;
use std::path::Path; use std::path::Path;
#[derive(Default)]
pub struct Parser { pub struct Parser {
#[allow(dead_code)] #[allow(dead_code)]
load_linkbases: bool, load_linkbases: bool,
@@ -11,9 +11,7 @@ pub struct Parser {
impl Parser { impl Parser {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self::default()
load_linkbases: false,
}
} }
pub fn parse_file<P: AsRef<Path>>(&self, path: P) -> Result<Document> { pub fn parse_file<P: AsRef<Path>>(&self, path: P) -> Result<Document> {
@@ -43,7 +41,7 @@ impl Parser {
concept_ids: vec![0; fact_count], concept_ids: vec![0; fact_count],
context_ids: vec![0; fact_count], context_ids: vec![0; fact_count],
unit_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], decimals: vec![None; fact_count],
ids: vec![None; fact_count], ids: vec![None; fact_count],
footnote_refs: vec![], footnote_refs: vec![],
@@ -68,14 +66,14 @@ impl Parser {
// Add dummy contexts // Add dummy contexts
for i in 0..context_count { for i in 0..context_count {
doc.contexts.push(Context { doc.contexts.push(Context {
id: CompactString::new(&format!("ctx{}", i)), id: String::from(&format!("ctx{}", i)),
entity: Entity { entity: Entity {
identifier: CompactString::new("0000000000"), identifier: String::from("0000000000"),
scheme: CompactString::new("http://www.sec.gov/CIK"), scheme: String::from("http://www.sec.gov/CIK"),
segment: None, segment: None,
}, },
period: Period::Instant { period: Period::Instant {
date: CompactString::new("2023-12-31"), date: String::from("2023-12-31"),
}, },
scenario: None, scenario: None,
}); });
@@ -84,10 +82,10 @@ impl Parser {
// Add dummy units // Add dummy units
for i in 0..unit_count { for i in 0..unit_count {
doc.units.push(Unit { doc.units.push(Unit {
id: CompactString::new(&format!("unit{}", i)), id: String::from(&format!("unit{}", i)),
unit_type: UnitType::Simple(vec![Measure { unit_type: UnitType::Simple(vec![Measure {
namespace: CompactString::new("iso4217"), namespace: String::from("iso4217"),
name: CompactString::new("USD"), name: String::from("USD"),
}]), }]),
}); });
} }

View File

@@ -42,8 +42,8 @@ pub struct XbrlValidator {
decimal_tolerance: f64, decimal_tolerance: f64,
} }
impl XbrlValidator { impl Default for XbrlValidator {
pub fn new() -> Self { fn default() -> Self {
Self { Self {
strict_mode: false, strict_mode: false,
check_calculations: true, check_calculations: true,
@@ -54,6 +54,12 @@ impl XbrlValidator {
decimal_tolerance: 0.01, decimal_tolerance: 0.01,
} }
} }
}
impl XbrlValidator {
pub fn new() -> Self {
Self::default()
}
pub fn strict(mut self) -> Self { pub fn strict(mut self) -> Self {
self.strict_mode = true; self.strict_mode = true;
@@ -117,8 +123,7 @@ impl XbrlValidator {
} }
// Validate period // Validate period
match &ctx.period { if let Period::Duration { start, end } = &ctx.period {
Period::Duration { start, end } => {
if start > end { if start > end {
errors.push(ValidationError::InvalidDataType { errors.push(ValidationError::InvalidDataType {
concept: format!("context_{}", ctx.id), concept: format!("context_{}", ctx.id),
@@ -127,8 +132,6 @@ impl XbrlValidator {
}); });
} }
} }
_ => {}
}
} }
errors errors
@@ -226,10 +229,13 @@ impl XbrlValidator {
} }
} }
// Type alias for validation rules
type ValidationRule = Box<dyn Fn(&Document) -> Vec<ValidationError>>;
// Validation context and rules // Validation context and rules
pub struct ValidationContext { pub struct ValidationContext {
pub profile: ValidationProfile, pub profile: ValidationProfile,
pub custom_rules: Vec<Box<dyn Fn(&Document) -> Vec<ValidationError>>>, pub custom_rules: Vec<ValidationRule>,
} }
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]