From 0fa2892e08fb19bf4f492ab03851977d10f376a2 Mon Sep 17 00:00:00 2001 From: Pavel Mikhalkevich Date: Sat, 24 Aug 2024 12:09:39 +0400 Subject: [PATCH] Add docs rules --- .github/workflows/test.yml | 2 +- Cargo.toml | 6 ++++++ Makefile | 1 + src/client/builder.rs | 4 +++- src/client/mod.rs | 1 + src/client/public.rs | 9 +++++---- src/lib.rs | 4 ++++ src/queue.rs | 2 ++ 8 files changed, 23 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3a37e17..fc1e4ed 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -208,7 +208,7 @@ jobs: - name: cargo llvm-cov env: POSTGRES_URL: postgres://username:password@127.0.0.1:5444/pgboss - run: cargo llvm-cov --locked --all-features --test e2e --lcov --output-path lcov.info -- include-ignored + run: cargo llvm-cov --locked --all-features --lcov --output-path lcov.info -- --include-ignored - name: Record Rust version run: echo "RUST=$(rustc --version)" >> "$GITHUB_ENV" - name: Upload to codecov.io diff --git a/Cargo.toml b/Cargo.toml index da48522..7567526 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,8 @@ categories = ["asynchronous"] exclude = [".github", "docker", ".gitignore", "Makefile"] +[features] +default = [] [dependencies] chrono = { version = "0.4.38", features = [] } @@ -25,3 +27,7 @@ sqlx = { version = "0.8.0", features = [ [dev-dependencies] lazy_static = "1.5.0" tokio = { version = "1.39.2", features = ["macros", "rt"] } + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] diff --git a/Makefile b/Makefile index 7491839..bc981f9 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ check: cargo clippy --all-features cargo d --no-deps --all-features +# https://users.rust-lang.org/t/how-to-document-optional-features-in-api-docs/64577/3 .PHONY: doc doc: RUSTDOCFLAGS='--cfg docsrs' cargo +nightly d --all-features --open diff --git a/src/client/builder.rs b/src/client/builder.rs index 7117375..49b074a 100644 --- a/src/client/builder.rs +++ b/src/client/builder.rs @@ -3,6 +3,7 @@ use sqlx::postgres::{PgConnectOptions, PgPool}; use super::{opts, Client}; use crate::utils; +/// Builder for [`Client`]. #[derive(Debug, Clone)] pub struct ClientBuilder { schema: String, @@ -17,6 +18,7 @@ impl Default for ClientBuilder { } impl ClientBuilder { + /// Schema name. pub fn schema(mut self, schema: S) -> Self where S: Into, @@ -37,7 +39,7 @@ impl ClientBuilder { self.use_pool(pool).await } - // Connect to the PostgreSQL server using specific `PgConnectOptions` + /// Connect to the PostgreSQL server using specific `PgConnectOptions` pub async fn connect_with(opts: PgConnectOptions) -> Result { let pool = utils::create_pool_with(opts).await?; Client::use_pool(pool).await diff --git a/src/client/mod.rs b/src/client/mod.rs index 79bf9b9..672566e 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -7,6 +7,7 @@ mod public; pub use builder::ClientBuilder; +/// PgBoss client. #[derive(Debug, Clone)] pub struct Client { pool: PgPool, diff --git a/src/client/public.rs b/src/client/public.rs index 672d2ce..2846173 100644 --- a/src/client/public.rs +++ b/src/client/public.rs @@ -7,11 +7,12 @@ use sqlx::postgres::PgConnectOptions; use sqlx::postgres::PgPool; use sqlx::types::Json; -use super::{builder, opts, Client}; +use super::{builder::ClientBuilder, opts, Client}; impl Client { - pub fn builder() -> builder::ClientBuilder { - builder::ClientBuilder::default() + /// Create an instance of [`ClientBuilder`] + pub fn builder() -> ClientBuilder { + ClientBuilder::default() } /// Connect to the PostgreSQL server. @@ -26,7 +27,7 @@ impl Client { Client::use_pool(pool).await } - // Connect to the PostgreSQL server using specific `PgConnectOptions` + /// Connect to the PostgreSQL server using specific `PgConnectOptions` pub async fn connect_with(opts: PgConnectOptions) -> Result { let pool = utils::create_pool_with(opts).await?; Client::use_pool(pool).await diff --git a/src/lib.rs b/src/lib.rs index 873b109..52f2584 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,7 @@ +//! Crate docs +#![deny(missing_docs)] +#![cfg_attr(docsrs, feature(doc_cfg))] + mod client; mod job; mod queue; diff --git a/src/queue.rs b/src/queue.rs index 17df1f5..88295ac 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -23,7 +23,9 @@ impl std::fmt::Display for QueuePolicy { } } +/// Queue configuration. #[derive(Debug, Clone, Default, Serialize)] pub struct QueueOptions { + /// Policy to apply to this queue. pub policy: QueuePolicy, }