diff --git a/Cargo.toml b/Cargo.toml index 7669400f..d3b3b8a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,8 @@ readme = "README.md" default = ["apollo_tracing", "bson", "chrono", "chrono-tz", "log", "multipart", "tracing", "url"] apollo_tracing = ["chrono"] multipart = ["multer", "bytes", "tempfile"] +# Used for doc(cfg()) +nightly = [] [dependencies] async-graphql-derive = { path = "derive", version = "2.0.0-alpha.8" } @@ -52,6 +54,9 @@ tempfile = { version = "3.1.0", optional = true } [dev-dependencies] async-std = { version = "1.5.0", features = ["attributes"] } +[package.metadata.docs.rs] +features = ["nightly"] + [workspace] members = [ "parser", diff --git a/src/error.rs b/src/error.rs index 7089f21c..3a5f796b 100644 --- a/src/error.rs +++ b/src/error.rs @@ -331,6 +331,7 @@ pub enum ParseRequestError { /// The request's multipart data was invalid. #[error("Invalid multipart data")] #[cfg(feature = "multipart")] + #[cfg_attr(feature = "nightly", doc(cfg(feature = "multipart")))] InvalidMultipart(multer::Error), /// Missing "operators" part for multipart request. diff --git a/src/extensions/apollo_tracing.rs b/src/extensions/apollo_tracing.rs index 7c5c1d0a..92d90718 100644 --- a/src/extensions/apollo_tracing.rs +++ b/src/extensions/apollo_tracing.rs @@ -51,6 +51,7 @@ impl Serialize for ResolveStat { /// have access to performance traces alongside the data returned by your query. /// It's already supported by `Apollo Engine`, and we're excited to see what other kinds of /// integrations people can build on top of this format. +#[cfg_attr(feature = "nightly", doc(cfg(feature = "apollo_tracing")))] pub struct ApolloTracing { start_time: DateTime, end_time: DateTime, diff --git a/src/extensions/logger.rs b/src/extensions/logger.rs index ed07ae70..eab4e180 100644 --- a/src/extensions/logger.rs +++ b/src/extensions/logger.rs @@ -7,6 +7,7 @@ use std::borrow::Cow; use uuid::Uuid; /// Logger extension +#[cfg_attr(feature = "nightly", doc(cfg(feature = "log")))] pub struct Logger { id: Uuid, enabled: bool, diff --git a/src/extensions/tracing.rs b/src/extensions/tracing.rs index 5e438319..7f2c5ee7 100644 --- a/src/extensions/tracing.rs +++ b/src/extensions/tracing.rs @@ -8,8 +8,9 @@ use uuid::Uuid; /// /// # References /// -/// https://crates.io/crates/tracing +/// #[derive(Default)] +#[cfg_attr(feature = "nightly", doc(cfg(feature = "tracing")))] pub struct Tracing { root_id: Option, fields: BTreeMap, diff --git a/src/http/mod.rs b/src/http/mod.rs index 7e4e4079..79a5c921 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -21,6 +21,7 @@ use futures::AsyncReadExt; /// If the content type is multipart it will use `receive_multipart`, otherwise it will use /// `receive_json`. #[cfg(feature = "multipart")] +#[cfg_attr(feature = "nightly", doc(cfg(feature = "multipart")))] pub async fn receive_body( content_type: Option>, body: impl AsyncRead + Send + 'static, diff --git a/src/http/multipart.rs b/src/http/multipart.rs index c65d2c33..79fea22c 100644 --- a/src/http/multipart.rs +++ b/src/http/multipart.rs @@ -12,6 +12,7 @@ use std::task::{Context, Poll}; /// Options for `receive_multipart`. #[derive(Default, Clone)] #[non_exhaustive] +#[cfg_attr(feature = "nightly", doc(cfg(feature = "multipart")))] pub struct MultipartOptions { /// The maximum file size. pub max_file_size: Option, @@ -38,6 +39,7 @@ impl MultipartOptions { } /// Receive a multipart request. +#[cfg_attr(feature = "nightly", doc(cfg(feature = "multipart")))] pub async fn receive_multipart( body: impl AsyncRead + Send + 'static, boundary: impl Into, diff --git a/src/lib.rs b/src/lib.rs index 0d03c1eb..bcfc7d4a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -59,8 +59,8 @@ //! Licensed under either of //! //! * Apache License, Version 2.0, -//! (./LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0) -//! * MIT license (./LICENSE-MIT or http://opensource.org/licenses/MIT) +//! (./LICENSE-APACHE or ) +//! * MIT license (./LICENSE-MIT or ) //! at your option. //! //! ## References @@ -91,12 +91,25 @@ //! //! Now a HTML report is available at `benchmark/target/criterion/report`. //! +//! # Crate features +//! +//! This crate offers the following features, all of which are activated by default: +//! +//! - `apollo_tracing`: Enable the [Apollo tracing +//! extension](extensions/struct.ApolloTracing.html). +//! - `log`: Enable the [logger extension](extensions/struct.Logger.html). +//! - `tracing`: Enable the [tracing extension](extensions/struct.Tracing.html). +//! - `multipart`: Support [sending files over HTTP multipart](http/fn.receive_multipart.html). +//! - `bson`: Integrate with the [`bson` crate](https://crates.io/crates/bson). +//! - `chrono`: Integrate with the [`chrono` crate](https://crates.io/crates/chrono). +//! - `chrono-tz`: Integrate with the [`chrono-tz` crate](https://crates.io/crates/chrono-tz). +//! - `url`: Integrate with the [`url` crate](https://crates.io/crates/url). #![warn(missing_docs)] -#![allow(clippy::needless_lifetimes)] #![allow(clippy::trivially_copy_pass_by_ref)] #![recursion_limit = "256"] #![forbid(unsafe_code)] +#![cfg_attr(feature = "nightly", feature(doc_cfg))] mod base; mod context; diff --git a/src/types/id.rs b/src/types/id.rs index 81bd3bc8..a9afa7d0 100644 --- a/src/types/id.rs +++ b/src/types/id.rs @@ -10,6 +10,7 @@ use std::ops::{Deref, DerefMut}; /// /// The input is a `&str`, `String`, `usize` or `uuid::UUID`, and the output is a string. #[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Serialize, Deserialize)] +#[serde(transparent)] pub struct ID(pub String); impl Deref for ID {