Skip to main content

rdice_core/
lib.rs

1#![warn(missing_docs)]
2//! Core dice primitives and roll orchestration for `rdice`.
3//!
4//! `rdice_core` owns the domain model used by the command-line and terminal
5//! interfaces: dice, trays, roll expressions, random rolls, and deterministic
6//! roll analysis.
7//!
8//! # Quick start
9//!
10//! ```
11//! use rdice_core::{DiceEngine, FaceValue, parse_roll_exprs};
12//!
13//! let mut engine = DiceEngine::new();
14//! engine.create_die(
15//!     "Coin",
16//!     vec![FaceValue::Text("heads".into()), FaceValue::Text("tails".into())],
17//! )?;
18//!
19//! let parsed = parse_roll_exprs(&["2d6", "Coin", "3"])?;
20//! let analysis = engine.analyze_roll(&parsed.dice, &parsed.modifiers)?;
21//!
22//! assert_eq!(analysis.point_range.min, 5);
23//! assert_eq!(analysis.point_range.max, 15);
24//!
25//! # Ok::<(), rdice_core::DiceError>(())
26//! ```
27//!
28//! # Naming
29//!
30//! Built-in dice are exposed with uppercase names such as `D6` and `D20`.
31//! Numeric roll expressions are case-insensitive, so `d6` and `D6` resolve to
32//! the same die. Custom dice are stored with [`CUSTOM_PREFIX`] internally, but
33//! API methods that accept die names also accept the unprefixed custom name.
34
35/// Dice definitions and face values.
36pub mod die;
37/// Roll execution, roll analysis, and tray operations.
38pub mod engine;
39/// Error and result types returned by the crate.
40pub mod error;
41/// Parsing helpers for compact dice roll expressions.
42pub mod expr;
43/// Tray data structures used to group persistent dice slots.
44pub mod tray;
45
46pub use die::{CUSTOM_PREFIX, Die, DieKind, FaceValue, builtin_dice};
47pub use engine::{
48    DiceEngine, DieRoll, PointRange, RollAnalysis, RollBatchResult, SlotResult, TrayResult,
49};
50pub use error::{DiceError, Result};
51pub use expr::{ParsedRoll, parse_dice_only_exprs, parse_roll_exprs};
52pub use tray::{Tray, TraySlot};