cedar_policy/lib.rs
1/*
2 * Copyright Cedar Contributors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17// Includes the cedar-policy README as the top-level documentation for this
18// crate. This also acts as a test that the example code in the README
19// compiles. If changing the docs away from using the readme verbatim, be sure
20// to add a separate test specifically for README examples by introducing a
21// private, empty, and unused function with `#[doc = include_str!("../README.md")]`.
22#![doc = include_str!("../README.md")]
23//!
24//! # Feature flags
25//!
26//! ## Default features
27//!
28//! The following features are enabled by default and provide the built-in Cedar
29//! extension functions:
30//!
31//! - `ipaddr` — IP address extension functions (`ip`, `isIpv4`, `isIpv6`,
32//! `isLoopback`, `isMulticast`, `isInRange`).
33//! - `decimal` — Decimal number extension functions (`decimal`, `lessThan`,
34//! `lessThanOrEqual`, `greaterThan`, `greaterThanOrEqual`).
35//! - `datetime` — Date and time extension functions (`datetime`, `duration`,
36//! `offset`, `durationSince`, `toDate`, `toTime`). Enables the `chrono`
37//! dependency.
38//!
39//! ## Optional features
40//!
41//! - `heap-profiling` — Enables heap profiling via `dhat`.
42//! - `corpus-timing` — Enables corpus timing instrumentation.
43//! - `wasm` — Enables WebAssembly bindings via `wasm-bindgen` and `tsify`.
44//!
45//! ## Experimental features
46//!
47//! **WARNING:** Experimental features are unstable and subject to breaking
48//! changes in any release, including patch releases. Use those features at your
49//! own risk.
50//!
51//! - `experimental` — Enables all experimental features listed below.
52//! - `variadic-is-in-range` — Variadic overload for the `isInRange` function.
53//! - `tpe` — Type-aware partial evaluation / batched authorization.
54//! - `partial-eval` — Partial evaluation of Cedar policies. You should prefer `tpe` above.
55//! - `partial-validate` — Partial validation of Cedar policies.
56//! - `permissive-validate` — Permissive validation mode.
57//! - `protobufs` — Protocol Buffers serialization support for Cedar types.
58//! Enables the `proto` module.
59//! - `tolerant-ast` — Error-tolerant parsing that produces a (possibly
60//! incomplete) AST even when the input contains syntax errors. This feature is intended
61//! only for use in language servers, and should never be used on the authorization path.
62//! - `extended-schema` — Extended schema support intended for language servers.
63//! - (deprecated) `deprecated-schema-compat` — Support for deprecated schema parsing
64//! behavior. API is stable, but will be removed in a future release.
65//! - (deprecated) `entity-manifest` — Entity manifest computation for entity slicing.
66//! This feature is deprecated; you should use `tpe` instead.
67#![warn(clippy::pedantic, clippy::use_self, clippy::option_if_let_else)]
68#![deny(
69 missing_docs,
70 rustdoc::broken_intra_doc_links,
71 rustdoc::private_intra_doc_links,
72 rustdoc::invalid_codeblock_attributes,
73 rustdoc::invalid_html_tags,
74 rustdoc::invalid_rust_codeblocks,
75 rustdoc::bare_urls,
76 clippy::doc_markdown,
77 clippy::doc_lazy_continuation,
78 clippy::too_long_first_doc_paragraph
79)]
80#![allow(
81 clippy::must_use_candidate,
82 reason = "in the future we can enable this lint but currently it doesn't pass"
83)]
84// enable doc_cfg feature if docsrs cfg is present
85#![cfg_attr(docsrs, feature(doc_cfg))]
86#![cfg_attr(
87 feature = "wasm",
88 allow(
89 non_snake_case,
90 reason = "Wasm/TypeScript doesn't use snake case identifiers by convention"
91 )
92)]
93
94/// Rust public API
95mod api;
96
97pub use api::version::{get_lang_version, get_sdk_version};
98pub use api::*;
99
100/// FFI utilities, see comments in the module itself
101pub mod ffi;
102
103/// Protobuf models of cedar-policy types
104#[cfg(feature = "protobufs")]
105#[cfg_attr(docsrs, doc(cfg(feature = "protobufs")))]
106pub mod proto;
107
108mod test;