From 1c185c22a8f69db35aec3f6df448064ca03e40b7 Mon Sep 17 00:00:00 2001 From: Beefki Date: Sat, 4 Nov 2017 22:15:56 -0500 Subject: [PATCH] Less failure, better comments --- src/roll.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/roll.rs b/src/roll.rs index f515124..37a8aef 100644 --- a/src/roll.rs +++ b/src/roll.rs @@ -1,20 +1,19 @@ //! A struct in which our data is held for rolling. By ensuring that //! only `usize`s are used we prevent the need for additional type -//! checking at time of use. */ +//! checking at time of use. extern crate rand; use rand::Rng; use std::fmt; use std::num::ParseIntError; use super::std; -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, PartialEq)] pub struct Roll { die: usize, number: usize, } impl Roll { - /// A fn to create new `Roll` structs, private to prevent - /// being used outside the library. + /// A function to create new `Roll` structs. pub fn new(number: usize, die: usize) -> Roll { Roll { die: die, @@ -26,7 +25,7 @@ impl Roll { ///Allows the fields of `Roll` to be private (and unchangable) ///while still allowing access to act on their internal value /// ``` - /// let x = Roll::new(&2, &6); + /// let x = Roll::new(2, 6); /// assert!(x.number() == 2); /// ``` pub fn number(&self) -> usize { @@ -41,14 +40,14 @@ impl Roll { /// Creates a Vector to hold each of the values rolled. Making /// a Vector ensures the ability to work on exactly the same /// die rolls easily and accurately, since calling the `Roll` - /// iterator again will produce new results. + /// iterator again will produce new results. Consumes the `Roll` pub fn rolls(self) -> Vec { self.collect() } /// Used on a `Roll` to return only the final value, ignoring /// the values used to add up to that result. Allows `.total()` - /// syntax when used + /// syntax when used. Consumes the `Roll`. pub fn total(self) -> usize { self.sum() } @@ -123,8 +122,9 @@ fn displays() { #[test] fn rolls() { let x = Roll::new(20, 6); - for y in x.clone().rolls() { - assert!(y <= x.die()); + let y = x.die; + for z in x.rolls() { + assert!(z <= y); } } #[test]