Skip to main content

fiscal_core/
lib.rs

1//! Core types, tax computation, and XML generation for Brazilian fiscal documents.
2//!
3//! `fiscal-core` is the foundation crate of the `fiscal-rs` workspace. It contains:
4//!
5//! - **Data types** ([`types`], [`newtypes`]) — strongly-typed structs and newtypes for
6//!   NF-e / NFC-e document data, validated at construction time.
7//! - **Tax computation** ([`tax_icms`], [`tax_pis_cofins_ipi`], [`tax_issqn`], [`tax_is`]) —
8//!   build XML fragments for each Brazilian tax group and accumulate invoice totals.
9//! - **XML builder** ([`xml_builder`]) — typestate builder for assembling a complete,
10//!   schema-compliant NF-e / NFC-e XML document.
11//! - **Protocol helpers** ([`complement`], [`contingency`], [`qrcode`]) — attach SEFAZ
12//!   authorization protocols, manage contingency mode, and build NFC-e QR codes.
13//! - **Utilities** ([`format_utils`], [`xml_utils`], [`gtin`], [`state_codes`],
14//!   [`status_codes`], [`constants`]) — formatting, XML escaping, GTIN validation,
15//!   IBGE state code lookups, and SEFAZ status-code constants.
16//! - **Conversion** ([`convert`], [`standardize`]) — TXT-to-XML converter and
17//!   XML type identification / JSON conversion.
18//! - **Traits** ([`traits`]) — sealed `TaxCalculation` and `XmlSerializable` traits.
19
20pub mod config;
21pub mod error;
22pub use error::FiscalError;
23
24/// Functions for attaching SEFAZ authorization protocols to signed XML documents.
25pub mod complement;
26/// Compile-time constants: namespaces, algorithm URIs, and payment type codes.
27pub mod constants;
28/// Contingency mode manager for NF-e fallback emission.
29pub mod contingency;
30/// SPED TXT-to-XML converter for NF-e documents.
31pub mod convert;
32/// Formatting helpers for monetary amounts, rates, and decimal numbers.
33pub mod format_utils;
34/// GTIN (barcode) validation and check-digit calculation.
35pub mod gtin;
36/// Parse-don't-validate newtypes for monetary amounts, tax rates, access keys, and state codes.
37pub mod newtypes;
38/// NFC-e QR code URL builder and XML injection.
39pub mod qrcode;
40/// ASCII sanitization for XML text content (replaces accented characters).
41pub mod sanitize;
42/// NF-e XML document type identification and XML-to-JSON conversion.
43pub mod standardize;
44/// Brazilian state IBGE code lookup tables and helpers.
45pub mod state_codes;
46/// SEFAZ status code constants and valid-status sets.
47pub mod status_codes;
48/// Internal tax element types used by tax computation modules.
49pub mod tax_element;
50/// IBS/CBS (Imposto sobre Bens e Servicos / Contribuicao sobre Bens e Servicos) XML generation.
51pub mod tax_ibs_cbs;
52/// ICMS tax computation and XML generation (CST and CSOSN variants).
53pub mod tax_icms;
54/// IS (Imposto Seletivo) XML generation.
55pub mod tax_is;
56/// ISSQN (municipal service tax) XML generation.
57pub mod tax_issqn;
58/// PIS, COFINS, IPI, and II tax computation and XML generation.
59pub mod tax_pis_cofins_ipi;
60/// Timezone lookup by Brazilian state (UF).
61pub mod timezone;
62/// Public data structures for NF-e / NFC-e documents.
63pub mod types;
64/// Typestate XML builder for NF-e / NFC-e documents.
65pub mod xml_builder;
66/// XML building primitives: `tag`, `escape_xml`, and `extract_xml_tag_value`.
67pub mod xml_utils;
68
69/// Sealed trait infrastructure for preventing external implementations.
70pub mod sealed;
71/// Sealed public traits: [`TaxCalculation`](traits::TaxCalculation) and [`XmlSerializable`](traits::XmlSerializable).
72pub mod traits;