dbc-rs 0.5.0

Database CAN (DBC) parsing and editing library
Documentation
//! # dbc-rs
//!
//! A `no_std` compatible Rust library for parsing and working with DBC (CAN database) files.
//!
//! ## Features
//!
//! - **`no_std` compatible**: Works in embedded environments without the standard library
//! - **Minimal dependencies**: Only `heapless` when using `heapless` feature (zero dependencies with `alloc`/`std`)
//! - **Memory efficient**: Uses `Vec` (via `alloc`) for dynamic collections
//! - **Type-safe**: Strong typing for all DBC elements
//!
//! ## Usage
//!
//! ```rust,no_run
//! use dbc_rs::Dbc;
//!
//! let dbc_content = r#"VERSION "1.0"
//!
//! BU_: ECM TCM
//!
//! BO_ 256 EngineData : 8 ECM
//!  SG_ RPM : 0|16@0+ (0.25,0) [0|8000] "rpm" TCM
//! "#;
//!
//! let dbc = Dbc::parse(dbc_content)?;
//! # Ok::<(), dbc_rs::Error>(())
//! ```

#![cfg_attr(not(feature = "std"), no_std)]
#![deny(unused_must_use)]
#![forbid(unsafe_code)]

#[cfg(feature = "std")]
extern crate std;

#[cfg(all(feature = "alloc", not(feature = "heapless")))]
extern crate alloc;

#[cfg(feature = "attributes")]
mod attribute;
mod bit_timing;
mod byte_order;
mod compat;
mod dbc;
mod error;
mod extended_multiplexing;
mod message;
mod nodes;
mod parser;
mod receivers;
mod signal;
mod value_descriptions;
mod version;

// Builder infrastructure
// Note: Macros are available in all configurations since they're compile-time only
// and have no runtime dependencies. Builders themselves are std-only.
mod macros;

// High-performance wrapper (std-only)
#[cfg(feature = "std")]
mod fast_dbc;

#[cfg(feature = "attributes")]
pub use attribute::{
    AttributeDefinition, AttributeObjectType, AttributeTarget, AttributeValue, AttributeValueType,
};
pub use bit_timing::BitTiming;
pub use byte_order::ByteOrder;
pub use dbc::{Dbc, DecodedSignal};
pub use error::{Error, Result};
pub use extended_multiplexing::ExtendedMultiplexing;
pub use message::{Message, Signals};
pub use nodes::{Node, Nodes};
pub use receivers::Receivers;
pub use signal::Signal;
pub use value_descriptions::ValueDescriptions;
pub use version::Version;

/// Builders
#[cfg(all(feature = "std", feature = "attributes"))]
pub use attribute::AttributeDefinitionBuilder;
#[cfg(feature = "std")]
pub use bit_timing::BitTimingBuilder;
#[cfg(feature = "std")]
pub use dbc::DbcBuilder;
#[cfg(feature = "std")]
pub use extended_multiplexing::ExtendedMultiplexingBuilder;
#[cfg(feature = "std")]
pub use message::MessageBuilder;
#[cfg(feature = "std")]
pub use nodes::NodesBuilder;
#[cfg(feature = "std")]
pub use receivers::ReceiversBuilder;
#[cfg(feature = "std")]
pub use signal::SignalBuilder;
#[cfg(feature = "std")]
pub use value_descriptions::ValueDescriptionsBuilder;
#[cfg(feature = "std")]
pub use version::VersionBuilder;

// High-performance wrapper
#[cfg(feature = "std")]
pub use fast_dbc::FastDbc;

pub(crate) use parser::Parser;

/// The version of this crate as specified in `Cargo.toml`.
///
/// This constant is only available when the `std` feature is enabled.
#[cfg(feature = "std")]
pub const PKG_VERSION: &str = env!("CARGO_PKG_VERSION");

/// The DBC file format specification document.
///
/// This is the complete specification in Markdown format, useful for
/// documentation and reference purposes.
///
/// This constant is only available when the `std` feature is enabled.
#[cfg(feature = "std")]
pub const SPECIFICATION: &str = include_str!("../SPECIFICATIONS.md");

// Maximum limits for two-pass parsing (no alloc)
// Note: All MAX_* constants are now defined in limits.rs (generated by build.rs)
// and can be overridden at build time via environment variables:
// - DBC_MAX_MESSAGES (default: 8192, must be power of 2 for heapless)
// - DBC_MAX_SIGNALS_PER_MESSAGE (default: 64)
// - DBC_MAX_NODES (default: 256)
// - DBC_MAX_VALUE_DESCRIPTIONS (default: 64)
// - DBC_MAX_NAME_SIZE (default: 32, per DBC specification)
include!(concat!(env!("OUT_DIR"), "/limits.rs"));

// DBC file format keywords
pub(crate) const VERSION: &str = "VERSION";
pub(crate) const CM_: &str = "CM_";
pub(crate) const NS_: &str = "NS_";
pub(crate) const BS_: &str = "BS_";
pub(crate) const BU_: &str = "BU_";
pub(crate) const BO_: &str = "BO_";
pub(crate) const SG_: &str = "SG_";
pub(crate) const VAL_TABLE_: &str = "VAL_TABLE_";
pub(crate) const BA_DEF_: &str = "BA_DEF_";
pub(crate) const BA_DEF_DEF_: &str = "BA_DEF_DEF_";
pub(crate) const BA_: &str = "BA_";
pub(crate) const VAL_: &str = "VAL_";
pub(crate) const SIG_GROUP_: &str = "SIG_GROUP_";
pub(crate) const SIG_VALTYPE_: &str = "SIG_VALTYPE_";
pub(crate) const EV_: &str = "EV_";
pub(crate) const BO_TX_BU_: &str = "BO_TX_BU_";

// Additional keywords used in code
pub(crate) const VECTOR_XXX: &str = "Vector__XXX";
pub(crate) const SG_MUL_VAL_: &str = "SG_MUL_VAL_";