From 3395f5282e0dee2bd2e95d8d43d2ba917862bdc9 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 26 Oct 2024 15:37:56 +0300 Subject: [PATCH] docs(crate): Generate documenation for traits enabled by optional features --- Cargo.toml | 4 ++++ src/lib.rs | 5 +++++ src/lua.rs | 6 ++++-- src/python.rs | 3 +-- src/wasm.rs | 4 ++-- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7b97f9c..fd4b96c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -106,6 +106,10 @@ predicates = "3.1" [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(build)'] } +[package.metadata.docs.rs] +features = ["luamodule", "luajit", "pythonmodule", "wasm"] +rustdoc-args = ["--cfg", "docsrs"] + [package.metadata.git-cliff.git] protect_breaking_commits = true commit_parsers = [ diff --git a/src/lib.rs b/src/lib.rs index a376ecf..03ecaa7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LGPL-3.0-only #![doc = include_str!("../README.md")] +#![cfg_attr(docsrs, feature(doc_cfg))] mod content; mod types; @@ -10,15 +11,19 @@ pub use content::Chunk; pub use types::{Case, Locale, StyleGuide}; #[cfg(feature = "cli")] +#[doc(hidden)] pub mod cli; #[cfg(feature = "luamodule")] +#[doc(hidden)] pub mod lua; #[cfg(feature = "pythonmodule")] +#[doc(hidden)] pub mod python; #[cfg(feature = "wasm")] +#[doc(hidden)] pub mod wasm; mod en; diff --git a/src/lua.rs b/src/lua.rs index f0de114..03fd502 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -4,8 +4,6 @@ use crate::*; use mlua::prelude::*; -pub use crate::types::{Case, Locale, Result, StyleGuide}; - #[mlua::lua_module] fn decasify(lua: &Lua) -> LuaResult { let exports = lua.create_table()?; @@ -35,6 +33,7 @@ fn decasify(lua: &Lua) -> LuaResult { Ok(exports) } +#[cfg_attr(docsrs, doc(cfg(feature = "luamodule")))] impl FromLua for Chunk { fn from_lua(value: LuaValue, _: &Lua) -> LuaResult { match value { @@ -44,6 +43,7 @@ impl FromLua for Chunk { } } +#[cfg_attr(docsrs, doc(cfg(feature = "luamodule")))] impl FromLua for Locale { fn from_lua(value: LuaValue, _: &Lua) -> LuaResult { match value { @@ -54,6 +54,7 @@ impl FromLua for Locale { } } +#[cfg_attr(docsrs, doc(cfg(feature = "luamodule")))] impl FromLua for Case { fn from_lua(value: LuaValue, _: &Lua) -> LuaResult { match value { @@ -64,6 +65,7 @@ impl FromLua for Case { } } +#[cfg_attr(docsrs, doc(cfg(feature = "luamodule")))] impl FromLua for StyleGuide { fn from_lua(value: LuaValue, _: &Lua) -> LuaResult { match value { diff --git a/src/python.rs b/src/python.rs index d964113..31f8dd9 100644 --- a/src/python.rs +++ b/src/python.rs @@ -1,10 +1,9 @@ // SPDX-FileCopyrightText: © 2023 Caleb Maclennan // SPDX-License-Identifier: LGPL-3.0-only +use crate::*; use pyo3::prelude::*; -pub use crate::types::{Case, Locale, Result, StyleGuide}; - #[pymodule] fn decasify(module: &Bound<'_, PyModule>) -> PyResult<()> { module.add_class::()?; diff --git a/src/wasm.rs b/src/wasm.rs index bab53b9..64e4d91 100644 --- a/src/wasm.rs +++ b/src/wasm.rs @@ -1,11 +1,11 @@ // SPDX-FileCopyrightText: © 2023 Caleb Maclennan // SPDX-License-Identifier: LGPL-3.0-only +use crate::*; + use std::result::Result; use wasm_bindgen::prelude::*; -pub use crate::types::{Case, Locale, StyleGuide}; - #[wasm_bindgen] pub fn case(input: &str, case: Case, locale: Locale, style: StyleGuide) -> Result { Ok(crate::case(input, case, locale, style))