easyfix_core/lib.rs
1//! Core types for session-message decoupling in easyfix.
2//!
3//! This crate defines the contract between the session layer and generated
4//! message code: basic types, base messages, the [`SessionMessage`] trait, and
5//! deserialization error types.
6//!
7//! # Basic types
8//!
9//! Foundational FIX types (`FixStr`, `FixString`, `SeqNum`, `UtcTimestamp`,
10//! etc.) and user-facing field newtypes (`MsgTypeField`, `SessionStatusField`,
11//! `SessionRejectReasonField`) with their corresponding value traits.
12//!
13//! # Base messages
14//!
15//! Minimal typed structures (`HeaderBase`, `AdminBase`, etc.) containing only
16//! the fields the session needs, plus base enumerations (`MsgTypeBase`,
17//! `SessionStatusBase`, etc.) - typed constants for session-relevant FIX
18//! enumeration values. Used by [`SessionMessage`] implementations.
19//!
20//! # SessionMessage trait
21//!
22//! The session layer is generic over `M: SessionMessage`, so it never names a
23//! concrete message type. [`SessionMessage`] and [`HeaderAccess`] are
24//! implemented by generated code, bridging session logic to concrete message
25//! definitions.
26//!
27//! [`SessionMessage`]: crate::message::SessionMessage
28//! [`HeaderAccess`]: crate::message::HeaderAccess
29
30// `variant_count` backs the compile-time completeness guards on the base
31// enums' `ALL` slices in `base_messages`.
32#![feature(variant_count)]
33
34#[doc(hidden)]
35pub use easyfix_macros::validate_fix_str as __validate_fix_str;
36
37pub mod base_messages;
38pub mod basic_types;
39pub mod country;
40pub mod currency;
41pub mod deserializer;
42pub mod language;
43pub mod message;
44pub mod serializer;
45pub mod version;
46
47/// Builds a `&'static FixStr` from a string literal.
48///
49/// Every byte is checked at expansion time to be printable ASCII
50/// (`0x20`-`0x7e`); a literal containing anything else is a compile error
51/// naming the offending position. Usable in `const` context and in ordinary
52/// expressions alike, so it is the way to write a `FixStr` literal - reach
53/// for `FixStr::from_ascii_unchecked` only for runtime bytes, which this
54/// macro cannot see.
55///
56/// ```
57/// # use easyfix_core::{basic_types::FixStr, fix_str};
58/// const BEGIN_STRING: &FixStr = fix_str!("FIXT.1.1");
59/// assert_eq!(BEGIN_STRING.as_utf8(), "FIXT.1.1");
60/// ```
61///
62/// ```compile_fail
63/// # use easyfix_core::fix_str;
64/// // SOH is a control character - rejected at compile time.
65/// let bad = fix_str!("FIXT\x01");
66/// ```
67#[macro_export]
68macro_rules! fix_str {
69 ($($input:tt)*) => {{
70 let literal = $crate::__validate_fix_str!($($input)*);
71 // SAFETY: the validator only emits printable ASCII string literals.
72 unsafe {
73 $crate::basic_types::FixStr::from_ascii_unchecked(literal.as_bytes())
74 }
75 }};
76}