Struct RollingRecord

Source
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: i32

The number of lowest dice dropped, clamped to the size of the result vector.

§highest_dropped: i32

The number of highest dice dropped, clamped to the size of the result vector.

Implementations§

Source§

impl RollingRecord

Source

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);
Source

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.

Source

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);
Source

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.

Source

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]);
}
Source

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

Source§

fn clone(&self) -> RollingRecord

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RollingRecord

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RollingRecord

Source§

fn default() -> RollingRecord

Returns the “default value” for a type. Read more
Source§

impl Display for RollingRecord

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for RollingRecord

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for RollingRecord

Source§

fn eq(&self, other: &RollingRecord) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for RollingRecord

Source§

impl StructuralPartialEq for RollingRecord

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V