pub struct RollingRecord {
pub kind: RollingRecordKind<i32>,
pub results: Vec<i32>,
pub lowest_dropped: i32,
pub highest_dropped: i32,
}Expand description
A record of a roll of dice. The record includes the results of each die in
a set of dice. RollStandardDice and RollCustomDice both populate a
RollingRecord in the frame’s rolling record set.
Fields§
§kind: RollingRecordKind<i32>The kind of rolling record.
results: Vec<i32>The results of each die in the roll.
lowest_dropped: i32The number of lowest dice dropped, clamped to the size of the result vector.
highest_dropped: i32The number of highest dice dropped, clamped to the size of the result vector.
Implementations§
Source§impl RollingRecord
impl RollingRecord
Sourcepub fn drop_lowest(&mut self, count: i32)
pub fn drop_lowest(&mut self, count: i32)
Mark the lowest count results as dropped, clamping the drop count to
the number of results.
§Parameters
count: The number of results to drop.
§Panics
Panics if count the receiver is
uninitialized.
§Examples
Roll 3D12 and drop the lowest result:
let mut rolling_record = roll_standard_dice(&mut rng(), 3, 12);
rolling_record.drop_lowest(1);
assert_eq!(rolling_record.results.len(), 3);
assert_eq!(rolling_record.lowest_dropped, 1);Roll 3D12, but try to drop 4 results:
let mut rolling_record = roll_standard_dice(&mut rng(), 3, 12);
rolling_record.drop_lowest(4);
assert_eq!(rolling_record.results.len(), 3);
assert_eq!(rolling_record.lowest_dropped, 3);Sourcepub fn lowest_dropped(&self) -> Vec<i32>
pub fn lowest_dropped(&self) -> Vec<i32>
Answer the results that have been dropped because they were the lowest.
§Returns
The lowest dropped results, in ascending order.
Sourcepub fn drop_highest(&mut self, count: i32)
pub fn drop_highest(&mut self, count: i32)
Mark the highest count results as dropped, clamping the drop count to
the number of results.
§Parameters
count: The number of results to drop.
§Panics
Panics if count the receiver is
uninitialized.
§Examples
Roll 5D8 and drop the highest result:
let mut rolling_record = roll_standard_dice(&mut rng(), 5, 8);
rolling_record.drop_highest(1);
assert_eq!(rolling_record.results.len(), 5);
assert_eq!(rolling_record.highest_dropped, 1);Roll 5D8, but try to drop 7 results:
let mut rolling_record = roll_standard_dice(&mut rng(), 5, 8);
rolling_record.drop_highest(7);
assert_eq!(rolling_record.results.len(), 5);
assert_eq!(rolling_record.highest_dropped, 5);Sourcepub fn highest_dropped(&self) -> Vec<i32>
pub fn highest_dropped(&self) -> Vec<i32>
Answer the results that have been dropped because they were the highest.
§Returns
The highest dropped results, in ascending order.
Sourcepub fn kept(&self) -> Vec<i32>
pub fn kept(&self) -> Vec<i32>
Answer the kept results, dropping the lowest and highest results as necessary.
§Returns
The kept results, in ascending order.
§Examples
Roll 4D6, drop the lowest and highest die, leaving the middle two:
let mut rolling_record = roll_standard_dice(&mut rng(), 4, 6);
rolling_record.drop_lowest(1);
rolling_record.drop_highest(1);
assert_eq!(rolling_record.lowest_dropped, 1);
assert_eq!(rolling_record.highest_dropped, 1);
let kept = rolling_record.kept();
assert_eq!(kept.len(), 2);
for result in rolling_record.lowest_dropped() {
assert!(result <= kept[0]);
}
for result in rolling_record.highest_dropped() {
assert!(result >= kept[kept.len() - 1]);
}Sourcepub fn sum(&mut self) -> i32
pub fn sum(&mut self) -> i32
Compute the sum of the results, dropping the lowest and highest results
as necessary. Clamp the drop counts to the range
[0, self.results.len()]. Saturate the sum on overflow. Consecutive
calls are idempotent.
§Returns
The sum of the results.
§Examples
Roll 5D12 and sum the results:
let mut rolling_record = roll_standard_dice(&mut rng(), 5, 12);
let sum = rolling_record.sum();
assert!(sum >= 5 && sum <= 60);Roll 4D6, drop the lowest and highest die, and sum the middle die:
let mut rolling_record = roll_standard_dice(&mut rng(), 4, 6);
rolling_record.drop_lowest(1);
rolling_record.drop_highest(1);
let sum = rolling_record.sum();
assert!(sum >= 2 && sum <= 12);Trait Implementations§
Source§impl Clone for RollingRecord
impl Clone for RollingRecord
Source§fn clone(&self) -> RollingRecord
fn clone(&self) -> RollingRecord
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RollingRecord
impl Debug for RollingRecord
Source§impl Default for RollingRecord
impl Default for RollingRecord
Source§fn default() -> RollingRecord
fn default() -> RollingRecord
Source§impl Display for RollingRecord
impl Display for RollingRecord
Source§impl Hash for RollingRecord
impl Hash for RollingRecord
Source§impl PartialEq for RollingRecord
impl PartialEq for RollingRecord
impl Eq for RollingRecord
impl StructuralPartialEq for RollingRecord
Auto Trait Implementations§
impl Freeze for RollingRecord
impl RefUnwindSafe for RollingRecord
impl Send for RollingRecord
impl Sync for RollingRecord
impl Unpin for RollingRecord
impl UnwindSafe for RollingRecord
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more