Skip to content

Commit

Permalink
Fix dumb "ignored doctest" warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
benfrankel committed Aug 21, 2024
1 parent 10dd799 commit 009c79b
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 25 deletions.
16 changes: 12 additions & 4 deletions src/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,15 @@ impl<S: State> CurrentMut<'_, S> {
///
/// # Example
///
/// ```ignore
/// ```
/// # /*
/// fn spawn_new_menu(menu: NextStateRef<Menu>) {
/// match menu.unwrap() {
/// Menu::Main => spawn_main_menu(),
/// Menu::Settings => spawn_settings_menu(),
/// }
/// }
/// # */
/// ```
#[derive(SystemParam)]
pub struct NextRef<'w, 's, S: State> {
Expand Down Expand Up @@ -157,11 +159,13 @@ impl<S: State> NextRef<'_, '_, S> {
///
/// # Example
///
/// ```ignore
/// ```
/// # /*
/// fn toggle_blue(mut color: NextMut<ColorState>) {
/// let mut color = color.unwrap_mut();
/// color.blue = !color.blue;
/// }
/// # */
/// ```
#[derive(SystemParam)]
pub struct NextMut<'w, 's, S: StateMut> {
Expand Down Expand Up @@ -288,10 +292,12 @@ impl<S: StateMut> NextMut<'_, '_, S> {
///
/// # Example
///
/// ```ignore
/// ```
/// # /*
/// fn same_red(color: FlushRef<ColorState>) -> bool {
/// color.will_trans(&ColorState::when(|x, y| x.red == y.red))
/// }
/// # */
/// ```
#[derive(SystemParam)]
pub struct FlushRef<'w, 's, S: State> {
Expand Down Expand Up @@ -362,11 +368,13 @@ impl<S: State> FlushRef<'_, '_, S> {
///
/// # Example
///
/// ```ignore
/// ```
/// # /*
/// fn copy_red_to_green(mut color: FlushMut<ColorState>) {
/// let (current, next) = color.unwrap_mut();
/// next.green = current.red;
/// }
/// # */
/// ```
#[derive(SystemParam)]
pub struct FlushMut<'w, 's, S: StateMut> {
Expand Down
16 changes: 12 additions & 4 deletions src/extra/bevy_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
//!
//! Opt in to [`BevyStatePlugin<S>`] for `GameState`:
//!
//! ```ignore
//! ```
//! # /*
//! #[derive(State, Clone, PartialEq, Eq, Hash, Debug, Default)]
//! #[state(bevy_state)]
//! enum GameState {
Expand All @@ -15,30 +16,37 @@
//! Loading,
//! Playing,
//! }
//! # */
//! ```
//!
//! Add `GameState` along with its [`BevyState`] wrapper:
//!
//! ```ignore
//! ```
//! # /*
//! app.init_state::<GameState>();
//! # */
//! ```
//!
//! Change `GameState` to drive `BevyState`:
//!
//! ```ignore
//! ```
//! # /*
//! app.add_systems(Update, GameState::Title.on_update(
//! GameState::Loading.enter().run_if(input_just_pressed(KeyCode::Enter)),
//! ));
//! # */
//! ```
//!
//! Change `BevyState` to drive `GameState` (e.g. using
//! [iyes_progress](https://github.com/IyesGames/iyes_progress)):
//!
//! ```ignore
//! ```
//! # /*
//! app.add_plugins(
//! ProgressPlugin::new(GameState::Loading.bevy())
//! .continue_to(GameState::Playing.bevy()),
//! );
//! # */
//! ```

#[cfg(feature = "bevy_app")]
Expand Down
8 changes: 6 additions & 2 deletions src/extra/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,23 @@
///
/// Define your own split state type as a newtype:
///
/// ```ignore
/// ```
/// # /*
/// #[derive(State, Clone, PartialEq, Eq)]
/// pub struct MyState(pub SplitState);
/// # */
/// ```
pub type SplitState = &'static str;

/// A macro for extending [`SplitState`] newtypes.
///
/// # Example
///
/// ```ignore
/// ```
/// # /*
/// add_to_split_state!(MyState, Foo, Bar);
/// add_to_split_state!(MyState, Quux);
/// # */
/// ```
#[macro_export]
macro_rules! add_to_split_state {
Expand Down
28 changes: 21 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,45 @@
//! Define your own [`State`](state::State) type using the
//! [derive macro](pyri_state_derive::State):
//!
//! ```ignore
//! ```
//! # /*
//! #[derive(State, Clone, PartialEq, Eq, Default)]
//! struct Level(pub usize);
//! # */
//! ```
//!
//! Add [`StatePlugin`](setup::StatePlugin) and initialize your state type:
//!
//! ```ignore
//! ```
//! # /*
//! app.add_plugins(StatePlugin).init_state::<Level>();
//! # */
//! ```
//!
//! Add update systems with [`StatePattern::on_update`](pattern::StatePattern::on_update):
//!
//! ```ignore
//! ```
//! # /*
//! app.add_systems(Update, (
//! Level::ANY.on_update(update_level_timer),
//! Level(10).on_update(update_boss_health_bar),
//! state!(Level(4..=6)).on_update(spawn_enemy_waves),
//! ));
//! # */
//! ```
//!
//! Add flush hooks with other [`StatePattern`](pattern::StatePattern) methods:
//!
//! ```ignore
//! ```
//! # /*
//! app.add_systems(StateFlush, (
//! // Short-hand for `on_exit` followed by `on_enter`.
//! Level::ANY.on_edge(despawn_old_level, spawn_new_level),
//! Level(10).on_enter(play_boss_music),
//! state!(Level(4 | 7 | 10)).on_enter(save_checkpoint),
//! Level::with(|x| x.0 < 4).on_enter(spawn_tutorial_popup),
//! ));
//! # */
//! ```

// Allow macros to refer to this crate as `pyri_state` internally.
Expand Down Expand Up @@ -131,22 +139,27 @@ pub mod prelude {
///
/// The derive macro requires `Clone`, `PartialEq`, and `Eq`:
///
/// ```ignore
/// ```
/// # /*
/// #[derive(State, Clone, PartialEq, Eq)]
/// enum GameState { ... }
/// # */
/// ```
///
/// They can be omitted if you disable the default options:
///
/// ```ignore
/// ```
/// # /*
/// #[derive(State)]
/// #[state(no_defaults)]
/// struct RawState;
/// # */
/// ```
///
/// The following options are provided:
///
/// ```ignore
/// ```
/// # /*
/// #[derive(State, Clone, PartialEq, Eq, Hash, Debug)]
/// #[state(
/// // Disable default plugins: detect_change, flush_event, apply_flush.
Expand All @@ -173,6 +186,7 @@ pub mod prelude {
/// before(RawState),
/// )]
/// struct ConfiguredState;
/// # */
/// ```
pub use pyri_state_derive::State;
}
4 changes: 3 additions & 1 deletion src/next_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ impl<S: State> Default for TriggerStateFlush<S> {
/// The default `NextState` type is [`NextStateBuffer`](buffer::NextStateBuffer).
/// You can set a different `NextState` type in the [derive macro](pyri_state_derive::State):
///
/// ```ignore
/// ```
/// # /*
/// #[derive(State, Clone, PartialEq, Eq)]
/// #[state(next(NextStateStack<Self>))]
/// enum MenuState { ... }
/// # */
/// ```
pub trait NextState: Resource {
/// The stored [`State`] type.
Expand Down
24 changes: 18 additions & 6 deletions src/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,10 @@ impl<S: State + Eq> StatePattern<S> for S {
///
/// The usual way to use `AnyStatePattern` is through the associated constant [`State::ANY`]:
///
/// ```ignore
/// ```
/// # /*
/// Level::ANY.on_enter(reset_timer)
/// # */
/// ```
pub struct AnyStatePattern<S: State>(pub(crate) PhantomData<S>);

Expand All @@ -159,9 +161,11 @@ impl<S: State> StatePattern<S> for AnyStatePattern<S> {
/// The usual way to construct this type is with the [`state!`](crate::state!) macro or
/// [`State::with`]:
///
/// ```ignore
/// ```
/// # /*
/// state!(Level(4 | 7 | 10)).on_enter(save_checkpoint)
/// Level::with(|x| x.0 < 4).on_refresh(my_systems)
/// # */
/// ```
#[derive(Clone)]
pub struct FnStatePattern<S: State, F>(F, PhantomData<S>)
Expand Down Expand Up @@ -257,11 +261,13 @@ impl<S: State, P1: StatePattern<S>, P2: StatePattern<S>> StateTransPattern<S> fo
///
/// The usual way to use this type is through the associated constant [`State::ANY_TO_ANY`]:
///
/// ```ignore
/// ```
/// # /*
/// Level::ANY_TO_ANY.on_trans(reset_timer)
///
/// // Equivalent to:
/// (Level::ANY, Level::ANY).on_trans(reset_timer)
/// # */
/// ```
///
#[derive(Clone)]
Expand All @@ -279,9 +285,11 @@ impl<S: State> StateTransPattern<S> for AnyStateTransPattern<S> {
/// The usual way to construct this type is with the [`state!`](crate::state!) macro or
/// [`State::when`]:
///
/// ```ignore
/// ```
/// # /*
/// state!(Level(2..=5 | 7) => Level(8 | 10)).on_enter(spawn_something_cool)
/// Level::when(|x, y| y.0 > x.0).on_enter(play_next_level_sfx)
/// # */
/// ```
#[derive(Clone)]
pub struct FnStateTransPattern<S: State, F>(F, PhantomData<S>)
Expand Down Expand Up @@ -313,14 +321,18 @@ where
///
/// State pattern-matching:
///
/// ```ignore
/// ```
/// # /*
/// state!(Level(4 | 7 | 10)).on_enter(save_checkpoint)
/// # */
/// ```
///
/// State transition pattern-matching:
///
/// ```ignore
/// ```
/// # /*
/// state!(Level(x @ 1..=3) => y if y.0 == 10 - x).on_trans(do_something_cool)
/// # */
/// ```
#[macro_export]
macro_rules! state {
Expand Down
4 changes: 3 additions & 1 deletion src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ use crate::{
///
/// This trait can be [derived](pyri_state_derive::State) or implemented manually:
///
/// ```ignore
/// ```
/// # /*
/// #[derive(State, Clone, PartialEq, Eq)]
/// enum GameState { ... }
///
Expand All @@ -26,6 +27,7 @@ use crate::{
/// impl State for MenuState {
/// type Next = NextStateBuffer<Self>;
/// }
/// # */
/// ```
///
/// The derive macro would also implement
Expand Down

0 comments on commit 009c79b

Please sign in to comment.