Skip to content

Commit

Permalink
Special attention to how to document phantom struct is no longer requ…
Browse files Browse the repository at this point in the history
…ired
  • Loading branch information
dtolnay committed Apr 25, 2022
1 parent 5e70bd4 commit 8804dd2
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 94 deletions.
45 changes: 0 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,51 +131,6 @@ fn f<'a>(arg: ContravariantLifetime<'a>) -> ContravariantLifetime<'static> {
struct Demo<A, #[contra] B, #[invariant] C>;
```

### 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<T: ?Sized>;

impl<T: ?Sized> MyPhantom<T> {
/// 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<T: ?Sized>;
}

/// Documentation goes here.
#[allow(type_alias_bounds)]
pub type MyPhantom<T: ?Sized> = private::MyPhantom<T>;

#[doc(hidden)]
pub use self::private::*;
```

### Use cases

Entirely up to your imagination. Just to name one, how about a typed registry
Expand Down
49 changes: 0 additions & 49 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: ?Sized>;
//!
//! impl<T: ?Sized> MyPhantom<T> {
//! /// 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<T: ?Sized>;
//! }
//!
//! /// Documentation goes here.
//! #[allow(type_alias_bounds)]
//! pub type MyPhantom<T: ?Sized> = private::MyPhantom<T>;
//!
//! #[doc(hidden)]
//! pub use self::private::*;
//! #
//! # fn main() {}
//! ```
//!
//! # Use cases
//!
//! Entirely up to your imagination. Just to name one, how about a typed
Expand Down

0 comments on commit 8804dd2

Please sign in to comment.