From 8804dd2bb2dc6aef2d76d0dfa8dcda7038381618 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 24 Apr 2022 17:14:21 -0700 Subject: [PATCH] Special attention to how to document phantom struct is no longer required --- README.md | 45 --------------------------------------------- src/lib.rs | 49 ------------------------------------------------- 2 files changed, 94 deletions(-) diff --git a/README.md b/README.md index 1d7bf1a..8d5b50c 100644 --- a/README.md +++ b/README.md @@ -131,51 +131,6 @@ fn f<'a>(arg: ContravariantLifetime<'a>) -> ContravariantLifetime<'static> { struct Demo; ``` -### Documentation - -There are two alternatives for how to handle Rustdoc documentation on publicly -exposed phantom types. - -You may provide documentation directly on the phantom struct in the obvious way, -but Rustdoc will blithely display the somewhat distracting implementation -details of the mechanism emitted by the `#[phantom]` macro. This way should be -preferred if you need to document any public methods, as methods will not be -visible in the other alternative. - -```rust -use ghost::phantom; - -/// Documentation. -#[phantom] -pub struct MyPhantom; - -impl MyPhantom { - /// Documentation on methods. - pub fn foo() {} -} -``` - -If you aren't adding methods or don't need methods to be rendered in the -documentation, the recommended idiom is as follows. Rustdoc will show a much -less distracting type signature and all of your trait impls, but will not show -inherent methods. - -```rust -mod private { - use ghost::phantom; - - #[phantom] - pub struct MyPhantom; -} - -/// Documentation goes here. -#[allow(type_alias_bounds)] -pub type MyPhantom = private::MyPhantom; - -#[doc(hidden)] -pub use self::private::*; -``` - ### Use cases Entirely up to your imagination. Just to name one, how about a typed registry diff --git a/src/lib.rs b/src/lib.rs index b514897..821e934 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -127,55 +127,6 @@ //! # fn main() {} //! ``` //! -//! # Documentation -//! -//! There are two alternatives for how to handle Rustdoc documentation on -//! publicly exposed phantom types. -//! -//! You may provide documentation directly on the phantom struct in the obvious -//! way, but Rustdoc will blithely display the somewhat distracting -//! implementation details of the mechanism emitted by the `#[phantom]` macro. -//! This way should be preferred if you need to document any public methods, as -//! methods will not be visible in the other alternative. -//! -//! ``` -//! use ghost::phantom; -//! -//! /// Documentation. -//! #[phantom] -//! pub struct MyPhantom; -//! -//! impl MyPhantom { -//! /// Documentation on methods. -//! pub fn foo() {} -//! } -//! # -//! # fn main() {} -//! ``` -//! -//! If you aren't adding methods or don't need methods to be rendered in the -//! documentation, the recommended idiom is as follows. Rustdoc will show a much -//! less distracting type signature and all of your trait impls, but will not -//! show inherent methods. -//! -//! ``` -//! mod private { -//! use ghost::phantom; -//! -//! #[phantom] -//! pub struct MyPhantom; -//! } -//! -//! /// Documentation goes here. -//! #[allow(type_alias_bounds)] -//! pub type MyPhantom = private::MyPhantom; -//! -//! #[doc(hidden)] -//! pub use self::private::*; -//! # -//! # fn main() {} -//! ``` -//! //! # Use cases //! //! Entirely up to your imagination. Just to name one, how about a typed