tokio_modbus/
lib.rs

1// SPDX-FileCopyrightText: Copyright (c) 2017-2025 slowtec GmbH <post@slowtec.de>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4#![doc = include_str!("../README.md")]
5// Opt-in for allowed-by-default lints (in alphabetical order)
6// See also: <https://doc.rust-lang.org/rustc/lints>
7#![warn(future_incompatible)]
8#![warn(let_underscore)]
9#![warn(missing_debug_implementations)]
10//#![warn(missing_docs)] // TODO
11#![warn(rust_2018_idioms)]
12#![warn(rust_2021_compatibility)]
13#![warn(unreachable_pub)]
14#![warn(unsafe_code)]
15#![warn(unused)]
16// Clippy lints
17#![warn(clippy::pedantic)]
18// Additional restrictions
19#![warn(clippy::clone_on_ref_ptr)]
20#![warn(clippy::self_named_module_files)]
21// Exceptions
22#![allow(clippy::enum_glob_use)]
23#![allow(clippy::similar_names)]
24#![allow(clippy::module_name_repetitions)]
25#![allow(clippy::wildcard_imports)] // TODO
26#![allow(clippy::missing_errors_doc)] // TODO
27
28/// Re-export the `bytes` crate
29///
30/// Needed to prevent version conflicts with types that are exposed by the public API.
31///
32/// Used by [`Response::Custom`].
33pub use bytes;
34
35pub mod prelude;
36
37pub mod client;
38
39pub mod slave;
40pub use self::slave::{Slave, SlaveId};
41
42mod codec;
43
44mod error;
45pub use self::error::{Error, ProtocolError};
46
47mod frame;
48#[cfg(feature = "server")]
49pub use self::frame::SlaveRequest;
50pub use self::frame::{
51    Address, ExceptionCode, ExceptionResponse, FunctionCode, Quantity, Request, Response,
52};
53
54/// Specialized [`std::result::Result`] type for type-checked responses of the _Modbus_ client API.
55///
56/// The payload is generic over the response type.
57///
58/// This [`Result`] type contains 2 layers of errors.
59///
60/// 1. [`Error`]: An unexpected protocol or network error that occurred during client/server communication.
61/// 2. [`ExceptionCode`]: An error occurred on the _Modbus_ server.
62pub type Result<T> = std::result::Result<std::result::Result<T, ExceptionCode>, Error>;
63
64mod service;
65
66#[cfg(feature = "server")]
67pub mod server;