doc: add roll 3d6 example
This commit is contained in:
6
01.workspace/oxidice_lib/examples/roll_3d6.rs
Normal file
6
01.workspace/oxidice_lib/examples/roll_3d6.rs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
use oxidice_lib::dice::*;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let outcome = Handful::grab(3, 6).roll();
|
||||||
|
println!("{outcome}");
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -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>;
|
||||||
|
|||||||
Reference in New Issue
Block a user