zenoh_keyexpr/lib.rs
1//
2// Copyright (c) 2023 ZettaScale Technology
3//
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7// which is available at https://www.apache.org/licenses/LICENSE-2.0.
8//
9// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10//
11// Contributors:
12//   ZettaScale Zenoh Team, <zenoh@zettascale.tech>
13//
14
15//! ⚠️ WARNING ⚠️
16//!
17//! This crate is intended for Zenoh's internal use.
18//!
19//! [Click here for Zenoh's documentation](https://docs.rs/zenoh/latest/zenoh)
20//!
21//! [Key expression](https://github.com/eclipse-zenoh/roadmap/blob/main/rfcs/ALL/Key%20Expressions.md) are Zenoh's address space.
22//!
23//! In Zenoh, operations are performed on keys. To allow addressing multiple keys with a single operation, we use Key Expressions (KE).
24//! KEs are a small language that express sets of keys through a glob-like language.
25//!
26//! These semantics can be a bit difficult to implement, so this module provides the following facilities:
27//!
28//! # Storing Key Expressions
29//! This module provides 2 flavours to store strings that have been validated to respect the KE syntax, and a third is provided by [`zenoh`](https://docs.rs/zenoh):
30//! - [`keyexpr`] is the equivalent of a [`str`],
31//! - [`OwnedKeyExpr`] works like an [`Arc<str>`](std::sync::Arc),
32//! - [`KeyExpr`](https://docs.rs/zenoh/latest/zenoh/key_expr/struct.KeyExpr.html) works like a [`Cow<str>`](std::borrow::Cow), but also stores some additional context internal to Zenoh to optimize
33//!   routing and network usage.
34//!
35//! All of these types [`Deref`](core::ops::Deref) to [`keyexpr`], which notably has methods to check whether a given [`keyexpr::intersects`] with another,
36//! or even if a [`keyexpr::includes`] another.
37//!
38//! # Tying values to Key Expressions
39//! When storing values tied to Key Expressions, you might want something more specialized than a [`HashMap`](std::collections::HashMap) if you want to respect
40//! the Key Expression semantics with high performance.
41//!
42//! Enter [KeTrees](keyexpr_tree). These are data-structures specially built to store KE-value pairs in a manner that supports the set-semantics of KEs.
43//!
44//! # Building and parsing Key Expressions
45//! A common issue in REST API is the association of meaning to sections of the URL, and respecting that API in a convenient manner.
46//! The same issue arises naturally when designing a KE space, and [`KeFormat`](format::KeFormat) was designed to help you with this,
47//! both in constructing and in parsing KEs that fit the formats you've defined.
48//!
49//! [`kedefine`](https://docs.rs/zenoh/latest/zenoh/key_expr/format/macro.kedefine.html) also allows you to define formats at compile time, allowing a more performant, but more importantly safer and more convenient use of said formats,
50//! as the [`keformat`](https://docs.rs/zenoh/latest/zenoh/key_expr/format/macro.keformat.html) and [`kewrite`](https://docs.rs/zenoh/latest/zenoh/key_expr/format/macro.kewrite.html) macros will be able to tell you if you're attempting to set fields of the format that do not exist.
51
52#![cfg_attr(not(feature = "std"), no_std)]
53extern crate alloc;
54
55pub mod key_expr;
56
57pub use key_expr::*;
58pub mod keyexpr_tree;