lnmp_core/
lib.rs

1#![allow(clippy::approx_constant)]
2
3//! # lnmp-core
4//!
5//! Core type definitions for LNMP (LLM Native Minimal Protocol).
6//!
7//! This crate provides the fundamental data structures for representing LNMP data:
8//! - [`FieldId`]: Type alias for field identifiers (u16, range 0-65535)
9//! - [`LnmpValue`]: Enum representing all supported value types
10//! - [`LnmpField`]: A field ID and value pair
11//! - [`LnmpRecord`]: A collection of fields representing a complete record
12//! - [`TypeHint`]: Type annotations for values (v0.2+)
13//!
14//! ## LNMP v0.2 Features
15//!
16//! Version 0.2 adds:
17//! - **Type hints**: Optional type annotations (`:i`, `:f`, `:b`, `:s`, `:sa`)
18//! - **Sorted fields**: `sorted_fields()` method for deterministic ordering
19//!
20//! ## Example
21//!
22//! ```
23//! use lnmp_core::{LnmpField, LnmpRecord, LnmpValue};
24//!
25//! // Create a new record
26//! let mut record = LnmpRecord::new();
27//!
28//! // Add fields
29//! record.add_field(LnmpField {
30//!     fid: 12,
31//!     value: LnmpValue::Int(14532),
32//! });
33//!
34//! record.add_field(LnmpField {
35//!     fid: 7,
36//!     value: LnmpValue::Bool(true),
37//! });
38//!
39//! // Access fields
40//! if let Some(field) = record.get_field(12) {
41//!     println!("Field 12: {:?}", field.value);
42//! }
43//!
44//! // Get sorted fields (v0.2)
45//! let sorted = record.sorted_fields();
46//! for field in sorted {
47//!     println!("F{} = {:?}", field.fid, field.value);
48//! }
49//! ```
50//!
51//! ## Type Hints (v0.2)
52//!
53//! ```
54//! use lnmp_core::{TypeHint, LnmpValue};
55//!
56//! // Parse type hint from string
57//! let hint = TypeHint::parse("i").unwrap();
58//! assert_eq!(hint.as_str(), "i");
59//!
60//! // Validate value matches type hint
61//! let value = LnmpValue::Int(42);
62//! assert!(hint.validates(&value));
63//! ```
64
65#![warn(missing_docs)]
66#![warn(clippy::all)]
67
68pub mod checksum;
69pub mod container;
70pub mod limits;
71pub mod record;
72pub mod types;
73
74pub use container::{
75    LnmpContainerError, LnmpContainerHeader, LnmpFileMode, LNMP_CONTAINER_VERSION_1,
76    LNMP_FLAG_CHECKSUM_REQUIRED, LNMP_FLAG_COMPRESSED, LNMP_FLAG_ENCRYPTED,
77    LNMP_FLAG_EXT_META_BLOCK, LNMP_FLAG_QKEX, LNMP_FLAG_QSIG, LNMP_HEADER_SIZE, LNMP_MAGIC,
78};
79pub use limits::{StructuralError, StructuralLimits};
80pub use record::{LnmpField, LnmpRecord};
81pub use types::{FieldId, LnmpValue, TypeHint};