ichen_openprotocol/lib.rs
1//! Rust access library to read/write iChen® 4 Open Protocol™ messages.
2//!
3//! Details on the protocol can be found in [this document].
4//!
5//! Design Notes
6//! ============
7//!
8//! Beware that all data types defined in this crate use borrowed string slices (i.e. `&str`) extensively.
9//! This is because the most common usage pattern is to create a data variable, set fields, immediately
10//! serialize it into JSON, then dispose of the data variable. The deserialization story is similar.
11//!
12//! Error values also borrow heavily from the input fields as these errors are expected to be handled
13//! as soon as possible.
14//!
15//! The result is minimal allocations and copying, but at the cost of stricter lifetime management,
16//! especially when deserializing -- the message struct cannot out-live the original JSON text string as
17//! fields are borrowed extensively from the original JSON string.
18//!
19//! Another implication due to extensive usage of borrowed string slices is that string literals with
20//! escape sequences will cause parsing errors because the actual string cannot be simply borrowed from
21//! the original JSON string. Luckily this is extremely rare for most fields holding names, ID's etc.
22//! For this reason, only certain user-defined text fields (such as `job_card_id`) may contain
23//! escaped characters (especially the double-quote); those are therefore modeled using `Cow<&str>` instead.
24//!
25//! [this document]: https://github.com/chenhsong/OpenProtocol/blob/master/cs/doc/messages_reference.md
26//!
27
28#![doc(html_logo_url = "https://chenhsong.github.io/iChen/images/ichen_40_logo_small.png")]
29#![doc(html_root_url = "https://docs.rs/ichen-openprotocol")]
30
31// Modules
32mod address;
33mod controller;
34mod error;
35mod filters;
36mod geo_location;
37mod job_card;
38mod key_value_pair;
39mod messages;
40mod operator;
41mod state_values;
42mod text;
43mod types;
44mod utils;
45
46/// Result type.
47pub type Result<'a, T> = std::result::Result<T, Error<'a>>;
48
49/// Result error type.
50pub type Error<'a> = OpenProtocolError<'a>;
51
52/// 32-bit real floating-point number.
53pub use noisy_float::types::R32;
54
55// Re-exports
56pub use address::Address;
57pub use controller::Controller;
58pub use error::OpenProtocolError;
59pub use filters::Filters;
60pub use geo_location::GeoLocation;
61pub use job_card::JobCard;
62pub use key_value_pair::KeyValuePair;
63pub use messages::*;
64pub use operator::Operator;
65pub use state_values::StateValues;
66pub use text::{TextID, TextName};
67pub use types::{ActionID, JobMode, Language, OpMode, ID};