Skip to main content

BufRand

Struct BufRand 

Source
pub struct BufRand<R: RngCore> {
    pub rand: R,
    /* private fields */
}
Expand description

used to generate random booleans using a bit buffer

Fields§

§rand: R

the inner randomizer of this BufRand. this is pub so it can be used after this BufRand has been Constructed

Implementations§

Source§

impl<R: RngCore> BufRand<R>

Source

pub fn new(rand: R) -> Self

create a new BufRand which generates random booleans using the supplied rng

Examples found in repository?
examples/random_bool.rs (line 4)
3fn main() {
4    let mut rand = BufRand::new(rand::thread_rng());
5    println!("{}", rand.next_bool());
6}
More examples
Hide additional examples
examples/random_case.rs (line 4)
3fn main() {
4    let mut rand = BufRand::new(rand::thread_rng());
5    println!("{}", rand.rand_string_case("Hello World!"));
6}
examples/inner_randomizer.rs (line 5)
4fn main() {
5    let mut buf_rand = BufRand::new(rand::thread_rng());
6    // the inner randomizer (rand) of buf_rand can still be used
7    buf_rand.rand.next_u32();
8}
Source

pub fn next_bool(&mut self) -> bool

returns a random boolean from the buffer of this BufRand

use buf_rand::BufRand;

let mut rand = BufRand::new(rand::thread_rng());
rand.next_bool();
Examples found in repository?
examples/random_bool.rs (line 5)
3fn main() {
4    let mut rand = BufRand::new(rand::thread_rng());
5    println!("{}", rand.next_bool());
6}
Source

pub fn rand_char_case(&mut self, c: &char) -> String

randomizes the capitalization of a char this returns a String since some chars may result in multiple when the case is changed such as this

// example of character turning into multiple
assert_eq!('ß'.to_uppercase().to_string(), "SS");
use buf_rand::BufRand;

let mut rand = BufRand::new(rand::thread_rng());
rand.rand_char_case(&'E');
Source

pub fn rand_string_case(&mut self, s: &str) -> String

randomizes the capitalization of every character in the string

use buf_rand::BufRand;

let mut rand = BufRand::new(rand::thread_rng());
rand.rand_string_case("hello world!");
Examples found in repository?
examples/random_case.rs (line 5)
3fn main() {
4    let mut rand = BufRand::new(rand::thread_rng());
5    println!("{}", rand.rand_string_case("Hello World!"));
6}

Auto Trait Implementations§

§

impl<R> Freeze for BufRand<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for BufRand<R>
where R: RefUnwindSafe,

§

impl<R> Send for BufRand<R>
where R: Send,

§

impl<R> Sync for BufRand<R>
where R: Sync,

§

impl<R> Unpin for BufRand<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for BufRand<R>
where R: UnsafeUnpin,

§

impl<R> UnwindSafe for BufRand<R>
where R: UnwindSafe,

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> 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, 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