Skip to main content

mesh/
lib.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Channel-based communication framework for OpenVMM and OpenHCL.
5//!
6//! mesh provides typed channels (`Sender<T>` / `Receiver<T>`) that work
7//! the same way whether the two ends are in the same process or in
8//! different ones. Components that communicate through mesh channels can
9//! be moved between processes without changing their code.
10//!
11//! This is the facade crate — it re-exports the important types from the
12//! lower-level `mesh_channel`, `mesh_node`, `mesh_protobuf`, and
13//! `mesh_derive` crates. Most code should only depend on this crate.
14//!
15//! # Channels
16//!
17//! - [`channel()`] — multi-producer channel (`Sender<T>` / `Receiver<T>`).
18//! - [`oneshot()`] — single-use transfer (`OneshotSender<T>` /
19//!   `OneshotReceiver<T>`).
20//! - [`rpc::Rpc`] — request/response: bundles a request with a reply
21//!   channel. The conventional pattern is an enum of `Rpc` variants.
22//! - [`Cell`] / [`CellUpdater`] — publish-subscribe for
23//!   configuration updates.
24//! - [`pipe`] — `AsyncRead` / `AsyncWrite` byte stream with backpressure.
25//! - [`CancelContext`] — cooperative cancellation with deadlines.
26//!
27//! # Message types
28//!
29//! Any type can be sent over a channel within a single process. To cross
30//! process boundaries, derive [`MeshPayload`]:
31//!
32//! ```rust,ignore
33//! use mesh::rpc::Rpc;
34//!
35//! #[derive(MeshPayload)]
36//! enum MyRequest {
37//!     DoThing(Rpc<Input, Output>),
38//!     Stop(Rpc<(), ()>),
39//! }
40//! ```
41//!
42//! `MeshPayload` types can include channel endpoints, file descriptors,
43//! and OS handles as fields — these are transferred automatically when
44//! the message crosses a process boundary.
45//!
46//! See the [mesh guide](https://openvmm.dev/guide/reference/architecture/openvmm/mesh.html)
47//! for a full introduction.
48
49#![expect(missing_docs)]
50#![forbid(unsafe_code)]
51
52#[expect(unused_extern_crates)]
53extern crate self as mesh;
54
55pub mod payload {
56    pub use mesh_derive::MeshProtobuf as Protobuf;
57    pub use mesh_protobuf::*;
58}
59
60pub use mesh_channel::ChannelError;
61pub use mesh_channel::ChannelErrorKind;
62pub use mesh_channel::OneshotReceiver;
63pub use mesh_channel::OneshotSender;
64pub use mesh_channel::Receiver;
65pub use mesh_channel::RecvError;
66pub use mesh_channel::Sender;
67pub use mesh_channel::TryRecvError;
68pub use mesh_channel::cancel::Cancel;
69pub use mesh_channel::cancel::CancelContext;
70pub use mesh_channel::cancel::CancelReason;
71pub use mesh_channel::cancel::Cancelled;
72pub use mesh_channel::cancel::Deadline;
73pub use mesh_channel::cell::Cell;
74pub use mesh_channel::cell::CellUpdater;
75pub use mesh_channel::cell::cell;
76pub use mesh_channel::channel;
77pub use mesh_channel::error;
78pub use mesh_channel::mpsc_channel;
79pub use mesh_channel::oneshot;
80pub use mesh_channel::pipe;
81pub use mesh_channel::rpc;
82pub use mesh_derive::MeshPayload;
83pub use mesh_node::common::Address;
84pub use mesh_node::common::NodeId;
85pub use mesh_node::common::PortId;
86pub use mesh_node::common::Uuid;
87pub use mesh_node::local_node;
88pub use mesh_node::message;
89pub use mesh_node::message::MeshPayload;
90pub use mesh_node::message::Message;
91pub use mesh_node::message::OwnedMessage;
92pub use mesh_node::resource;