Skip to content

Commit

Permalink
Apply the documentation approach recommended by ghost crate
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Nov 1, 2023
1 parent c05eed4 commit 8be1627
Showing 1 changed file with 41 additions and 40 deletions.
81 changes: 41 additions & 40 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,42 +199,39 @@ impl Registry {
}
}

macro_rules! document_iter {
($iter:item) => {
/// An iterator over plugins registered of a given type.
///
/// The value `inventory::iter::<T>` is an iterator with element type `&'static
/// T`.
///
/// There is no guarantee about the order that plugins of the same type are
/// visited by the iterator. They may be visited in any order.
///
/// # Examples
///
/// ```
/// # struct Flag {
/// # short: char,
/// # name: &'static str,
/// # }
/// #
/// # inventory::collect!(Flag);
/// #
/// # const IGNORE: &str = stringify! {
/// use my_flags::Flag;
/// # };
///
/// fn main() {
/// for flag in inventory::iter::<Flag> {
/// println!("-{}, --{}", flag.short, flag.name);
/// }
/// }
/// ```
///
/// Refer to the [crate level documentation](index.html) for a complete example
/// of instantiating a plugin registry and submitting plugins.
$iter
};
}
/// An iterator over plugins registered of a given type.
///
/// The value `inventory::iter::<T>` is an iterator with element type `&'static
/// T`.
///
/// There is no guarantee about the order that plugins of the same type are
/// visited by the iterator. They may be visited in any order.
///
/// # Examples
///
/// ```
/// # struct Flag {
/// # short: char,
/// # name: &'static str,
/// # }
/// #
/// # inventory::collect!(Flag);
/// #
/// # const IGNORE: &str = stringify! {
/// use my_flags::Flag;
/// # };
///
/// fn main() {
/// for flag in inventory::iter::<Flag> {
/// println!("-{}, --{}", flag.short, flag.name);
/// }
/// }
/// ```
///
/// Refer to the [crate level documentation](index.html) for a complete example
/// of instantiating a plugin registry and submitting plugins.
#[allow(non_camel_case_types)]
pub type iter<T> = private::iter<T>;

mod void_iter {
enum Void {}
Expand All @@ -247,20 +244,24 @@ mod void_iter {
}

mod value_iter {
pub use crate::iter::iter;
#[doc(hidden)]
pub use crate::private::iter::iter;
}

document_iter! {
mod private {
// Based on https://github.com/dtolnay/ghost
#[allow(non_camel_case_types)]
pub enum iter<T> {
__Phantom(void_iter::Iter<T>),
__Phantom(crate::void_iter::Iter<T>),
iter,
}

#[doc(hidden)]
pub use crate::value_iter::*;
}

#[doc(hidden)]
pub use crate::value_iter::*;
pub use crate::private::*;

const ITER: () = {
fn into_iter<T: Collect>() -> Iter<T> {
Expand Down

0 comments on commit 8be1627

Please sign in to comment.