From 576996aafd3265e13568bd285d054f78a60aa33b Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Mon, 4 Sep 2023 08:48:25 +0100 Subject: [PATCH] Ensure `dbs::Capabilities` are visible in Rust docs (#2593) --- lib/src/api/opt/capabilities.rs | 6 ++++++ lib/src/api/opt/mod.rs | 1 + lib/src/cnf/mod.rs | 2 +- lib/src/dbs/capabilities.rs | 38 +++++++++++++++++++++++++++++++++ lib/src/sql/mod.rs | 1 + 5 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 lib/src/api/opt/capabilities.rs diff --git a/lib/src/api/opt/capabilities.rs b/lib/src/api/opt/capabilities.rs new file mode 100644 index 00000000..5a0bfdbf --- /dev/null +++ b/lib/src/api/opt/capabilities.rs @@ -0,0 +1,6 @@ +//! The capabilities that can be enabled for a database instance + +pub use crate::dbs::capabilities::FuncTarget; +pub use crate::dbs::capabilities::NetTarget; +pub use crate::dbs::capabilities::Targets; +pub use crate::dbs::Capabilities; diff --git a/lib/src/api/opt/mod.rs b/lib/src/api/opt/mod.rs index 2ab09603..fde91240 100644 --- a/lib/src/api/opt/mod.rs +++ b/lib/src/api/opt/mod.rs @@ -1,6 +1,7 @@ //! The different options and types for use in API functions pub mod auth; +pub mod capabilities; mod config; mod endpoint; diff --git a/lib/src/cnf/mod.rs b/lib/src/cnf/mod.rs index d5071307..321cf32e 100644 --- a/lib/src/cnf/mod.rs +++ b/lib/src/cnf/mod.rs @@ -6,7 +6,7 @@ use once_cell::sync::Lazy; pub const MAX_CONCURRENT_TASKS: usize = 64; /// Specifies how deep various forms of computation will go before the query fails -/// with [`Error::ComputationDepthExceeded`]. +/// with [`crate::error::Db::ComputationDepthExceeded`]. /// /// For reference, use ~15 per MiB of stack in release mode. /// diff --git a/lib/src/dbs/capabilities.rs b/lib/src/dbs/capabilities.rs index 4769a2a2..53f2c0ed 100644 --- a/lib/src/dbs/capabilities.rs +++ b/lib/src/dbs/capabilities.rs @@ -174,6 +174,44 @@ impl std::fmt::Display fo /// - Allow all functions except `http.*`: `--allow-funcs --deny-funcs 'http.*'` /// - Allow all network addresses except AWS metadata endpoint: `--allow-net --deny-net='169.254.169.254'` /// +/// # Examples +/// +/// Create a new instance, and allow all capabilities +/// ```no_run +/// # use surrealdb::opt::capabilities::Capabilities; +/// # use surrealdb::opt::Config; +/// # use surrealdb::Surreal; +/// # use surrealdb::engine::local::File; +/// # #[tokio::main] +/// # async fn main() -> surrealdb::Result<()> { +/// let capabilities = Capabilities::all(); +/// let config = Config::default().capabilities(capabilities); +/// let db = Surreal::new::(("temp.db", config)).await?; +/// # Ok(()) +/// # } +/// ``` +/// +/// Create a new instance, and allow certain functions +/// ```no_run +/// # use std::str::FromStr; +/// # use surrealdb::engine::local::File; +/// # use surrealdb::opt::capabilities::Capabilities; +/// # use surrealdb::opt::capabilities::FuncTarget; +/// # use surrealdb::opt::capabilities::Targets; +/// # use surrealdb::opt::Config; +/// # use surrealdb::Surreal; +/// # #[tokio::main] +/// # async fn main() -> surrealdb::Result<()> { +/// let capabilities = Capabilities::default() +/// .with_functions(Targets::::All) +/// .without_functions(Targets::::Some( +/// [FuncTarget::from_str("http::*").unwrap()].into(), +/// )); +/// let config = Config::default().capabilities(capabilities); +/// let db = Surreal::new::(("temp.db", config)).await?; +/// # Ok(()) +/// # } +/// ``` #[derive(Debug, Clone)] pub struct Capabilities { scripting: bool, diff --git a/lib/src/sql/mod.rs b/lib/src/sql/mod.rs index b7b6ebbd..da18c5cc 100644 --- a/lib/src/sql/mod.rs +++ b/lib/src/sql/mod.rs @@ -87,6 +87,7 @@ pub use self::block::Block; pub use self::bytes::Bytes; pub use self::cast::Cast; pub use self::cond::Cond; +pub use self::constant::Constant; pub use self::data::Data; pub use self::datetime::Datetime; pub use self::dir::Dir;