fints-client 0.1.0

FinTS 3.0 PIN/TAN client for German online banking: accounts, balances, transactions, holdings, SEPA transfers and the payee check
Documentation
//! FinTS codec: wire syntax, data element types and declarative segments.
//!
//! - [`wire`]: tokenizer and serializer for the FinTS syntax (Formals H.1),
//!   ISO 8859-1, panic-free.
//! - [`types`]: the data element formats (Formals B.4): [`An`], [`Num`],
//!   [`Dig`], [`Jn`], [`Dat`], [`Tim`], [`Cur`], [`Wrt`], [`Btg`], [`Bin`],
//!   [`Id`], [`Code`].
//! - [`Segment`] / [`DataElementGroup`] derives: one struct per segment
//!   version or group, generating parse and serialise. Definitions live in
//!   [`defs`]; [`registry`] lists them for lookup by (code, version).
//! - [`schema`]: a static description of every definition
//!   ([`SegmentDef::schema`]), generated by the derives.
//! - Raw fallback: [`parse_message`] / [`parse_segment`] give
//!   [`ParsedSegment::Typed`], or [`ParsedSegment::Raw`] with the
//!   tokenized segment and the [`CodecError`] that kept it from being typed.
//!
//! How to add a segment: `docs/codec.md`.

// The crate-level `#![allow]` in lib.rs is for imported code; new code here
// is held to the full lint set.
#![warn(
    private_interfaces,
    clippy::too_many_arguments,
    clippy::upper_case_acronyms,
    clippy::large_enum_variant
)]
// Without the `tooling` feature the module is crate-internal and its public
// API goes unused.
#![cfg_attr(feature = "tooling", warn(dead_code))]

pub mod defs;
pub mod element;
pub mod error;
pub mod registry;
pub mod schema;
pub mod segment;
pub mod types;
pub mod wire;

#[cfg(test)]
mod derive_tests;

pub use crate::parser::{DEG, DataElement, RawSegment};
pub use element::{Cursor, Element, Rules};
pub use error::{CodecError, ErrorKind, SegmentId, WireError, WireErrorKind};
pub use fints_client_derive::{DataElementGroup, Segment};
pub use registry::{
    ParsedSegment, SegmentDef, TypedSegment, definitions, lookup, parse_message, parse_segment,
    parse_segments, read_segment, versions,
};
pub use schema::{ElementKind, FieldSchema};
pub use segment::{Segment, SegmentHeader, decode_segment, encode_segment, from_wire, to_wire};
pub use types::{An, Bin, Btg, Code, Cur, Dat, Dig, Id, Jn, Num, Scalar, Tim, Wrt};

/// Paths used by code that `fints-client-derive` generates. Not a stable API.
#[doc(hidden)]
pub mod __private {
    pub use crate::codec::element::{
        Cursor, Element, Rules, SlotReader, SlotWriter, assert_length_rules_allowed,
        decode_repeated, encode_repeated, repeat_width, seq_width,
    };
    pub use crate::codec::error::CodecError;
    pub use crate::codec::schema::{ElementKind, FieldSchema};
    pub use crate::codec::segment::Segment;
    pub use crate::parser::{DEG, DataElement};
}

/// Attribute misuse that must not compile.
///
/// An open repetition that is not the last element of its group:
///
/// ```compile_fail
/// use fints_client::codec::{An, DataElementGroup};
/// #[derive(DataElementGroup)]
/// struct Bad { list: Vec<An>, after: An }
/// ```
///
/// A group that ends in an open repetition, nested before another element:
///
/// ```compile_fail
/// use fints_client::codec::{An, DataElementGroup};
/// #[derive(DataElementGroup)]
/// struct Open { #[de(min_count = 1)] list: Vec<An> }
/// #[derive(DataElementGroup)]
/// struct Bad { open: Open, after: An }
/// ```
///
/// A repeated segment element without `max_count` that is not the last:
///
/// ```compile_fail
/// use fints_client::codec::{An, Segment};
/// #[derive(Segment)]
/// #[segment(code = "XBAD", version = 1)]
/// struct Bad { list: Vec<An>, after: An }
/// ```
///
/// A length rule on a group:
///
/// ```compile_fail
/// use fints_client::codec::{Btg, Segment};
/// #[derive(Segment)]
/// #[segment(code = "XBAD", version = 1)]
/// struct Bad { #[de(max = 3)] amount: Btg }
/// ```
///
/// Repetition counts on a field that is not a `Vec`, an unknown attribute,
/// both `max` and `len`, and a missing `#[segment]`:
///
/// ```compile_fail
/// use fints_client::codec::{An, Segment};
/// #[derive(Segment)]
/// #[segment(code = "XBAD", version = 1)]
/// struct Bad { #[de(max_count = 2)] one: An }
/// ```
///
/// ```compile_fail
/// use fints_client::codec::{An, Segment};
/// #[derive(Segment)]
/// #[segment(code = "XBAD", version = 1)]
/// struct Bad { #[de(maximum = 2)] one: An }
/// ```
///
/// ```compile_fail
/// use fints_client::codec::{An, Segment};
/// #[derive(Segment)]
/// #[segment(code = "XBAD", version = 1)]
/// struct Bad { #[de(max = 2, len = 2)] one: An }
/// ```
///
/// ```compile_fail
/// use fints_client::codec::{An, Segment};
/// #[derive(Segment)]
/// struct Bad { one: An }
/// ```
///
/// The same definitions written correctly compile:
///
/// ```
/// use fints_client::codec::{An, Btg, DataElementGroup, Segment};
/// #[derive(DataElementGroup)]
/// struct Good { after: An, list: Vec<An> }
/// #[derive(Segment)]
/// #[segment(code = "XGOOD", version = 1)]
/// struct GoodSeg { #[de(max_count = 3)] list: Vec<An>, amount: Btg, #[de(max = 2)] one: An }
/// ```
#[cfg(doctest)]
pub struct CompileFailTests;