bacnet_types/lib.rs
1//! BACnet protocol types per ASHRAE 135-2020.
2//!
3//! This crate provides the foundational types for the BACnet protocol:
4//! enumerations, primitive data types, addresses, and error types.
5//!
6//! Its runtime dependencies are `bitflags`, `smallvec` and `thiserror`.
7//!
8//! Every enum newtype implements `FromStr`, accepting any common case style
9//! (`analog-input`, `AnalogInput`, `ANALOG_INPUT`, ...) for its named
10//! constants. The optional `serde` feature adds `Deserialize` for
11//! [`enums::ObjectType`] and [`enums::PropertyIdentifier`] on top of it.
12//!
13//! # Features
14//!
15//! The crate needs an allocator, and one of these features to say so:
16//!
17//! - `std` (default): hosted builds. Adds the transport I/O error
18//! (`Error::Transport`) and the B/IP port contract (`bip_port`).
19//! - `alloc`: `no_std` with a global allocator, for bare-metal targets:
20//! `default-features = false, features = ["alloc"]`.
21//!
22//! A build with neither fails; that combination is reserved for a future
23//! allocation-free subset.
24
25// Tests always build with std, so feature-off test runs need no imports of
26// their own.
27#![cfg_attr(all(not(feature = "std"), not(test)), no_std)]
28
29// bacnet-encoding and bacnet-services pass their feature on to this crate, so
30// with neither on they stop here, before their own check can run.
31#[cfg(not(any(feature = "std", feature = "alloc")))]
32compile_error!(
33 "bacnet-types needs the `std` or the `alloc` feature \
34 (bacnet-encoding and bacnet-services pass theirs on)"
35);
36
37// `format!` and `vec!` without std's prelude.
38#[macro_use]
39extern crate alloc;
40
41#[cfg(feature = "std")]
42pub mod bip_port;
43pub mod bitstring;
44pub mod calendar;
45pub mod constructed;
46pub mod data_link;
47pub mod enums;
48pub mod error;
49pub mod network_number;
50pub mod primitives;
51
52/// BACnet MAC address — stack-allocated for typical sizes (≤6 bytes).
53///
54/// The data links this stack serves use 1-octet (MS/TP), 3-octet (the
55/// B/IPv6 VMAC) and 6-octet (B/IP, Ethernet, the B/SC VMAC) MACs, so SmallVec
56/// keeps every one of them inline.
57pub type MacAddr = smallvec::SmallVec<[u8; 6]>;