Skip to main content

msg_socket/
lib.rs

1//! # MSG Sockets
2//!
3//! This crate exposes a set of socket types that can be used to facilitate multiple communication
4//! patterns, such as:
5//! - Request-Reply
6//! - Publish-Subscribe
7//!
8//! Sockets are the main entrypoint in this library and facilitate all connectivity, like binding or
9//! connecting, and sending and receiving messages over connections.
10#![doc(issue_tracker_base_url = "https://github.com/chainbound/msg-rs/issues/")]
11#![cfg_attr(docsrs, feature(doc_cfg))]
12#![cfg_attr(not(test), warn(unused_crate_dependencies))]
13
14pub mod stats;
15
16pub mod hooks;
17pub use hooks::{ConnectionHook, Error as HookError, HookResult};
18
19// Re-export type-erased connection hook for internal use
20pub(crate) use hooks::ConnectionHookErased;
21
22#[path = "pub/mod.rs"]
23mod pubs;
24pub use pubs::{PubError, PubOptions, PubSocket};
25
26mod rep;
27pub use rep::*;
28
29mod req;
30pub use req::*;
31
32mod sub;
33pub use sub::*;
34
35mod connection;
36pub use connection::*;
37
38/// The default buffer size for a socket.
39pub const DEFAULT_BUFFER_SIZE: usize = 8192;
40
41/// The default queue size for a channel.
42pub const DEFAULT_QUEUE_SIZE: usize = 8192;
43
44/// A request Identifier.
45pub struct RequestId(u32);
46
47impl RequestId {
48    pub fn new(id: u32) -> Self {
49        Self(id)
50    }
51
52    pub fn id(&self) -> u32 {
53        self.0
54    }
55
56    pub fn increment(&mut self) {
57        self.0 = self.0.wrapping_add(1);
58    }
59}
60
61/// The performance profile to tune socket options for.
62#[derive(Debug, Clone, Default, Copy, PartialEq, Eq)]
63pub enum Profile {
64    /// Optimize for a balanced trade-off between latency and throughput.
65    #[default]
66    Balanced,
67    /// Optimize for low latency.
68    Latency,
69    /// Optimize for high throughput.
70    Throughput,
71}