Skip to main content

cradle_shared/
lib.rs

1//! # `cradle-shared`
2//! A library used by the `cradle` toolkit and its plugins that contains shared utilities and definitions
3#![warn(missing_docs)]
4
5/// Contains definitions for cradle checks
6pub mod checks;
7/// Constants shared by the agent and CLI
8pub mod consts;
9/// Errors shared by the cradle workspace
10pub mod errors;
11/// Small wrapper around an `Arc<Mutex<T>>` to make the code slightly cleaner
12pub mod mutex;
13#[cfg(feature = "tls")]
14/// Contains the code to allow the agent and cli to communicate over TLS.
15pub mod tls;
16
17pub use checks::*;
18pub use consts::*;
19pub use errors::*;
20pub use mutex::*;
21
22/// Small helper to convert a `&[u8]` to `Vec<u16>`
23pub fn bytes2wide(buf: &[u8]) -> Vec<u16> {
24    buf.chunks_exact(2)
25        .map(|c| u16::from_le_bytes([c[0], c[1]]))
26        .take_while(|&c| c != 0)
27        .collect()
28}