doc: add roll 3d6 example

This commit is contained in:
2025-11-16 08:40:10 +01:00
parent 0eddb019dd
commit 85194b3f0f
3 changed files with 27 additions and 8 deletions

View File

@@ -0,0 +1,6 @@
use oxidice_lib::dice::*;
fn main() {
let outcome = Handful::grab(3, 6).roll();
println!("{outcome}");
}

View File

@@ -12,3 +12,8 @@ pub(crate) use crate::str::die::O as Die;
pub(crate) use crate::str::failed_to::E as FailedTo; pub(crate) use crate::str::failed_to::E as FailedTo;
pub(crate) use crate::str::handful::O as Handful; pub(crate) use crate::str::handful::O as Handful;
pub(crate) use crate::str::outcome::E as Outcome; pub(crate) use crate::str::outcome::E as Outcome;
pub mod dice {
pub use crate::str::handful::O as Handful;
pub use crate::str::outcome::E as Outcome;
}

View File

@@ -1,5 +1,5 @@
use crate::*; use crate::*;
// use std::fmt::Display; use std::fmt::Display;
// use std::str::FromStr; // use std::str::FromStr;
#[derive(Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Hash)] #[derive(Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Hash)]
@@ -8,13 +8,21 @@ pub enum E {
List(Vec<u16>), List(Vec<u16>),
} }
// impl Display for E { impl Display for E {
// fn fmt(&self, f: &mut std::fmt::Formatter) -> std::result::Result<(), std::fmt::Error> { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::result::Result<(), std::fmt::Error> {
// match self { match self {
// Self::NoValue => write!(f, "NoValue"), Self::Scalar(value) => write!(f, "[{}]", value),
// } Self::List(value) => {
// } let str_list = value
// } .iter()
.map(|item| item.to_string())
.collect::<Vec<String>>()
.join(", ");
write!(f, "[{}]", str_list)
}
}
}
}
// impl FromStr for E { // impl FromStr for E {
// type Err = Box<dyn std::error::Error>; // type Err = Box<dyn std::error::Error>;