ockam_core/
lib.rs

1//! This crate contains the core types of the [Ockam][main-ockam-crate-link]
2//! library and is intended for use by crates that provide features and add-ons
3//! to the main [Ockam][main-ockam-crate-link] library.
4//!
5//! The main [Ockam][main-ockam-crate-link] crate re-exports types defined in
6//! this crate.
7//!
8//! ## Crate Features
9//!
10//! The `ockam_core` crate has a Cargo feature named `"std"` that is enabled by
11//! default. In order to use this crate in a `no_std` context this feature can
12//! be disabled as follows
13//!
14//! ```toml
15//! [dependencies]
16//! ockam_core = { version = "<current version>" , default-features = false }
17//! ```
18//!
19//! Please note that Cargo features are unioned across the entire dependency
20//! graph of a project. If any other crate you depend on has not opted out of
21//! `ockam_core` default features, Cargo will build `ockam_core` with the std
22//! feature enabled whether or not your direct dependency on `ockam_core`
23//! has `default-features = false`.
24//!
25#![deny(unsafe_code)]
26#![warn(
27    missing_docs,
28    trivial_casts,
29    trivial_numeric_casts,
30    unused_import_braces,
31    unused_qualifications
32)]
33#![cfg_attr(not(feature = "std"), no_std)]
34
35#[cfg(all(not(feature = "std"), not(feature = "alloc")))]
36compile_error!(r#"The "no_std" feature currently requires the "alloc" feature"#);
37
38#[cfg(feature = "std")]
39extern crate core;
40
41#[cfg(feature = "alloc")]
42#[macro_use]
43extern crate alloc;
44
45// Allow use of logging macros directly.
46#[macro_use]
47extern crate tracing;
48
49pub use async_trait::async_trait;
50
51/// Mark an Ockam Worker implementation.
52#[doc(inline)]
53pub use async_trait::async_trait as worker;
54/// Mark an Ockam Processor implementation.
55#[doc(inline)]
56pub use async_trait::async_trait as processor;
57
58extern crate ockam_macros;
59
60pub use ockam_macros::{Message, TryClone};
61
62extern crate futures_util;
63
64/// Access control
65pub mod access_control;
66pub mod api;
67pub mod compat;
68
69/// Debugger
70pub mod debugger;
71pub mod flow_control;
72
73/// Encoding
74pub mod hex_encoding;
75
76/// Environmental variables
77#[cfg(feature = "std")]
78pub mod env;
79
80pub mod bare;
81mod cbor;
82mod error;
83mod identity;
84mod message;
85mod processor;
86mod routing;
87mod uint;
88mod worker;
89
90pub use access_control::*;
91pub use cbor::*;
92pub use error::*;
93pub use identity::*;
94pub use message::*;
95pub use processor::*;
96pub use routing::*;
97pub use uint::*;
98pub use worker::*;
99
100#[cfg(all(not(feature = "std"), feature = "alloc"))]
101#[doc(hidden)]
102pub use compat::println;
103
104#[cfg(feature = "std")]
105#[doc(hidden)]
106pub use std::println;
107
108/// Clone trait when clone can fail.
109pub trait TryClone: Sized {
110    /// Try cloning an object and return an `Err` in case of failure.
111    fn try_clone(&self) -> Result<Self>;
112}
113
114impl<D> TryClone for D
115where
116    D: Clone + Sync,
117{
118    fn try_clone(&self) -> Result<Self> {
119        Ok(self.clone())
120    }
121}
122
123/// Produces Ok(false) to avoid an ambiguous reading from using the unadorned value in auth code.
124#[inline(always)]
125pub fn deny() -> Result<bool> {
126    Ok(false)
127}
128
129/// Produces Ok(true) to avoid an ambiguous reading from using the unadorned value in auth code.
130#[inline(always)]
131pub fn allow() -> Result<bool> {
132    Ok(true)
133}