Skip to content

Commit 5a3ca7b

Browse files
committed
feat(#6): add #[doc(hidden)] on private modules
1 parent 6ca289f commit 5a3ca7b

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
#[doc(hidden)]
12
pub mod gamestate;
3+
#[doc(hidden)]
24
pub mod render;
35
pub mod stream;
6+
#[doc(hidden)]
47
pub mod throttle;

src/render.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ fn prepare_grid(grid: &mut RenderGrid, game_state: Game) {
119119
}
120120

121121
/**
122-
* https://en.wikipedia.org/wiki/Box-drawing_character
122+
* `<https://en.wikipedia.org/wiki/Box-drawing_character>`
123123
*/
124124
fn render_line_wrapper(width: u32, top: bool) -> String {
125125
let line = (0..width)

src/stream.rs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ pub struct SizeOption {
1010
pub height: u32,
1111
}
1212

13+
/// Holds the options that were passed to the cli with a flag
14+
/// that are relevent for rendering the game.
1315
#[derive(Debug, Serialize, Deserialize, Clone)]
1416
#[serde(rename_all = "camelCase")]
1517
pub struct InitOptions {
@@ -62,6 +64,7 @@ impl fmt::Display for GameState {
6264
}
6365
}
6466

67+
/// Holds the state of the game at any time
6568
#[derive(Debug, Deserialize, Serialize, Clone)]
6669
pub struct Game {
6770
pub snake: Snake,
@@ -70,11 +73,11 @@ pub struct Game {
7073
pub state: GameState,
7174
}
7275

73-
/**
74-
* Accepts the iterator from `stdin().lines()`
75-
* - parses the first line into `option`
76-
* - returns an iterator of the other lines in `lines` (already parsed)
77-
*/
76+
/// Accepts the iterator from `stdin().lines()`
77+
/// - parses the first line into `options` as [InitOptions]
78+
/// - returns an iterator of [Game] inside `lines` (already parsed)
79+
///
80+
/// Used by [parse_gamestate] under the hood.
7881
pub struct Stream {
7982
pub options: InitOptions,
8083
pub lines: Box<dyn Iterator<Item = Game>>, // std::io::Lines<T>, //Lines<T>,
@@ -101,6 +104,27 @@ impl Stream {
101104
}
102105
}
103106

107+
/// Parses a gamestate streamed into stdin
108+
/// Example:
109+
/// ```
110+
/// match parse_gamestate() {
111+
/// Ok(stream) => {
112+
/// println!(
113+
/// "Frame duration {}, Snake length {}, Level {}x{}",
114+
/// stream.options.frame_duration,
115+
/// stream.options.snake_length,
116+
/// stream.options.size.width,
117+
/// stream.options.size.height
118+
/// );
119+
/// for parsed_line in stream.lines {
120+
/// do_something(parsed_lined);
121+
/// }
122+
/// }
123+
/// Err(e) => {
124+
/// println!("Error occurred while parsing stdin: \"{}\"", e);
125+
/// }
126+
/// }
127+
/// ```
104128
pub fn parse_gamestate() -> Result<Stream, Box<dyn std::error::Error>> {
105129
let lines = stdin().lines();
106130
Stream::new(lines)

0 commit comments

Comments
 (0)