zeek_websocket/
lib.rs

1//! # Rust types for interacting with Zeek over WebSocket
2//!
3//! This library provides types for interacting with [Zeek](https://zeek.org)'s
4//! WebSocket API.
5//!
6//! The main type of this crate is [`protocol::Binding`] which
7//! models [Zeek's WebSocket
8//! protocol](https://docs.zeek.org/projects/broker/en/master/web-socket.html). `Binding` depends
9//! on [`tungstenite`](https://docs.rs/tungstenite/) and uses lower-level data types defined in
10//! [`types`].
11//!
12//! Types in [`types`] can be used independently from `Binding` with any
13//! backend.
14//!
15//! The lowest-level type of the API is [`types::Value`] which allows converting
16//! between Zeek API types and Rust types, even user-defined types with [`ZeekType`].
17//!
18//! ## Feature flags
19#![doc = document_features::document_features!()]
20
21/// # Types of Zeek's WebSocket API
22///
23/// The main type of this module is [`Value`] which holds values of the Zeek API. Use its enum
24/// variants to create values of specific types, e.g.,
25///
26/// ```
27/// # use zeek_websocket::types::Value;
28/// let value1 = Value::Count(0);
29/// let value2 = Value::from(0u64);
30/// assert_eq!(value1, value2);
31/// ```
32///
33/// We provide implementations of [`TryFrom`] to go from Zeek values to Rust types, e.g.,
34///
35/// ```
36/// # use zeek_websocket::types::Value;
37/// assert_eq!(Value::Count(0).try_into(), Ok(0u64));
38/// assert_eq!(u16::try_from(Value::Count(0)), Ok(0u16));
39/// ```
40///
41/// User types can be serialized and deserialized with [`ZeekType`].
42///
43/// ```
44/// # use zeek_websocket::{Value, ZeekType};
45/// #[derive(ZeekType)]
46/// struct X {
47///     message: String,
48///     count: u64,
49/// }
50///
51/// let x = X { message: "Hello, world!".to_string(), count: 42 };
52/// let value = Value::from(x);
53/// let x = X::try_from(value);
54/// assert!(matches!(x, Ok(X{ count: 42, .. })));
55/// ```
56pub mod types {
57    #[doc(inline)]
58    pub use zeek_websocket_types::*;
59}
60#[doc(inline)]
61pub use types::*;
62
63#[cfg(feature = "tungstenite")]
64pub mod protocol;
65#[cfg(feature = "tungstenite")]
66#[doc(inline)]
67pub use protocol::Binding;
68
69#[cfg(feature = "tokio-client")]
70pub mod client;
71
72#[cfg(feature = "derive")]
73#[doc(inline)]
74pub use zeek_websocket_derive::ZeekType;