Skip to content

Commit 2a9c195

Browse files
authored
doc: Basic docs for forrustts-core (#255)
1 parent 853a022 commit 2a9c195

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

forrustts-core/src/lib.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
//! Core types for [`forrustts`](https://docs.rs/forrustts)
2+
3+
#![warn(missing_docs)]
4+
#![warn(rustdoc::broken_intra_doc_links)]
5+
#![cfg_attr(doc_cfg, feature(doc_cfg))]
6+
17
use thiserror::Error;
28

39
mod position;
@@ -9,8 +15,21 @@ mod time;
915
pub use position::Position;
1016
pub use time::Time;
1117

18+
/// Error type
1219
#[derive(Error, Debug)]
1320
pub enum Error {
21+
/// Invalid [`Position`]
22+
///
23+
/// # Example
24+
///
25+
/// ```
26+
/// if let Err(e) = forrustts_core::Position::try_from(-1) {
27+
/// assert!(matches!(e, forrustts_core::Error::PositionError(-1)));
28+
/// }
29+
/// # else {
30+
/// # panic!("should be an Err...");
31+
/// # }
32+
/// ```
1433
#[error("{0:?}")]
1534
PositionError(i64),
1635
}

forrustts-core/src/position.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@
44
pub struct Position(i64);
55

66
impl Position {
7+
/// Create a new Position
8+
///
9+
/// # Returns
10+
///
11+
/// * `Some` if `position` is non-negative
12+
/// * `None` otherwise
13+
///
14+
/// # Examples
15+
///
16+
/// ```
17+
/// let p = forrustts_core::Position::new(10).unwrap();
18+
/// assert_eq!(p, 10); // can be compared to i64
19+
/// # assert_eq!(10, p);
20+
/// # assert!(p > 0);
21+
/// # assert!(p != 0);
22+
/// # assert!(p >= 10);
23+
/// # assert!(p <= 10);
24+
/// # assert!(0 < p);
25+
/// let p2 = forrustts_core::Position::new(11).unwrap();
26+
/// assert!(p < p2);
27+
/// assert!(p != p2);
28+
/// ```
729
pub fn new(position: i64) -> Option<Self> {
830
if position >= 0 {
931
Some(Self(position))
@@ -12,6 +34,21 @@ impl Position {
1234
}
1335
}
1436

37+
/// Create a new position with a non-negative integer
38+
///
39+
/// # Examples
40+
///
41+
/// ```
42+
/// let p = forrustts_core::Position::new_valid(10);
43+
/// ```
44+
///
45+
/// # Panics
46+
///
47+
/// Will panic if `position` < 0.
48+
///
49+
/// ```should_panic
50+
/// let p = forrustts_core::Position::new(-1).unwrap();
51+
/// ```
1552
pub fn new_valid(position: i64) -> Self {
1653
Self::new(position).unwrap()
1754
}

forrustts-core/src/prelude.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
1+
//! Core library prelude
2+
//!
3+
//! # Examples
4+
//!
5+
//! ```
6+
//! use forrustts_core::prelude::*;
7+
//! ```
8+
19
pub use crate::Position;
210
pub use crate::Time;

0 commit comments

Comments
 (0)