mirror of
https://github.com/stefanoamorelli/crabrl.git
synced 2026-04-18 07:10:42 +00:00
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:
@@ -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
|
||||
|
||||
12
src/lib.rs
12
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 {
|
||||
|
||||
121
src/model.rs
121
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<u16>,
|
||||
pub values: Vec<FactValue>,
|
||||
pub decimals: Vec<Option<i8>>,
|
||||
pub ids: Vec<Option<CompactString>>,
|
||||
pub footnote_refs: Vec<Vec<CompactString>>,
|
||||
pub ids: Vec<Option<String>>,
|
||||
pub footnote_refs: Vec<Vec<String>>,
|
||||
}
|
||||
|
||||
#[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<CompactString>,
|
||||
pub concept: CompactString,
|
||||
pub context_ref: CompactString,
|
||||
pub unit_ref: Option<CompactString>,
|
||||
pub id: Option<String>,
|
||||
pub concept: String,
|
||||
pub context_ref: String,
|
||||
pub unit_ref: Option<String>,
|
||||
pub value: String,
|
||||
pub decimals: Option<i8>,
|
||||
pub precision: Option<u8>,
|
||||
pub nil: bool,
|
||||
pub nil_reason: Option<CompactString>,
|
||||
pub footnote_refs: Vec<CompactString>,
|
||||
pub nil_reason: Option<String>,
|
||||
pub footnote_refs: Vec<String>,
|
||||
}
|
||||
|
||||
// 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<Scenario>,
|
||||
@@ -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<Segment>,
|
||||
}
|
||||
|
||||
@@ -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<CompactString>,
|
||||
pub name: CompactString,
|
||||
pub id: Option<String>,
|
||||
pub name: String,
|
||||
pub facts: Vec<FactOrTuple>,
|
||||
}
|
||||
|
||||
@@ -160,11 +159,11 @@ pub enum FactOrTuple {
|
||||
// Footnote support
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Footnote {
|
||||
pub id: CompactString,
|
||||
pub role: Option<CompactString>,
|
||||
pub lang: Option<CompactString>,
|
||||
pub id: String,
|
||||
pub role: Option<String>,
|
||||
pub lang: Option<String>,
|
||||
pub content: String,
|
||||
pub fact_refs: Vec<CompactString>,
|
||||
pub fact_refs: Vec<String>,
|
||||
}
|
||||
|
||||
// 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<CompactString, SchemaElement>,
|
||||
pub types: HashMap<CompactString, SchemaType>,
|
||||
pub target_namespace: String,
|
||||
pub elements: HashMap<String, SchemaElement>,
|
||||
pub types: HashMap<String, SchemaType>,
|
||||
pub imports: Vec<SchemaImport>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SchemaElement {
|
||||
pub name: CompactString,
|
||||
pub element_type: CompactString,
|
||||
pub substitution_group: Option<CompactString>,
|
||||
pub period_type: Option<CompactString>,
|
||||
pub balance: Option<CompactString>,
|
||||
pub name: String,
|
||||
pub element_type: String,
|
||||
pub substitution_group: Option<String>,
|
||||
pub period_type: Option<String>,
|
||||
pub balance: Option<String>,
|
||||
pub abstract_element: bool,
|
||||
pub nillable: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SchemaType {
|
||||
pub name: CompactString,
|
||||
pub base_type: Option<CompactString>,
|
||||
pub name: String,
|
||||
pub base_type: Option<String>,
|
||||
pub restrictions: Vec<TypeRestriction>,
|
||||
}
|
||||
|
||||
@@ -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<Link>,
|
||||
}
|
||||
|
||||
@@ -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<i32>,
|
||||
pub use_attribute: Option<CompactString>,
|
||||
pub use_attribute: Option<String>,
|
||||
}
|
||||
|
||||
#[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<CompactString, String>,
|
||||
pub role: String,
|
||||
pub parts: HashMap<String, String>,
|
||||
}
|
||||
|
||||
// Main document structure with full XBRL support
|
||||
@@ -295,11 +294,11 @@ pub struct Document {
|
||||
pub label_links: Vec<LabelLink>,
|
||||
pub reference_links: Vec<ReferenceLink>,
|
||||
pub custom_links: Vec<Link>,
|
||||
pub role_types: Vec<CompactString>,
|
||||
pub arcrole_types: Vec<CompactString>,
|
||||
pub role_types: Vec<String>,
|
||||
pub arcrole_types: Vec<String>,
|
||||
pub schemas: Vec<Schema>,
|
||||
pub dimensions: Vec<DimensionMember>,
|
||||
pub concept_names: Vec<CompactString>,
|
||||
pub concept_names: Vec<String>,
|
||||
}
|
||||
|
||||
impl Default for Document {
|
||||
|
||||
@@ -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<P: AsRef<Path>>(&self, path: P) -> Result<Document> {
|
||||
@@ -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"),
|
||||
}]),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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<dyn Fn(&Document) -> Vec<ValidationError>>;
|
||||
|
||||
// Validation context and rules
|
||||
pub struct ValidationContext {
|
||||
pub profile: ValidationProfile,
|
||||
pub custom_rules: Vec<Box<dyn Fn(&Document) -> Vec<ValidationError>>>,
|
||||
pub custom_rules: Vec<ValidationRule>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
|
||||
Reference in New Issue
Block a user