Struct RandomBlock

Source
pub struct RandomBlock { /* private fields */ }
Expand description

Builder for generating random strings or bytes.

§Generation.

There are 2 (actually 3) types of byte generation. The underneath concept is to generate random bytes for both UTF8 strings and bytes or byte sequences. This generator breaks up the sequence of characters or bytes and from the sequence of combinations it will generate a series of random bytes. if the sequence of bytes are generated from a valid UTF8 string, then each letter can be seperated and used for generating a random sequence of the valid sequences of bytes. This allows for the byte -> UTF8 convertion to be almost infallible.

This also means that if the system is supplied with a set of words the generator can randomly put those words together into a sequence.

use randomizer::Randomizer;

let string = Randomizer::ALPHABETICAL(6).string().unwrap();

assert_eq!(string.chars().count(), 6 );

Implementations§

Source§

impl RandomBlock

§Public RandomBlock Implementation

Source

pub fn inner(&self) -> &Vec<u8>

§Inner reference

Getting the [‘RandomBlock’] inner data as a reference.

use randomizer::RandomBlock;

let random_block = RandomBlock::default();

assert_eq!(random_block.inner(), &Vec::new());
Source

pub fn inner_mut(&mut self) -> &mut Vec<u8>

§Inner mutable reference

Getting the [‘RandomBlock’] inner data as a mutable reference.

use randomizer::RandomBlock;

let mut random_block = RandomBlock::default();

*random_block.inner_mut() = vec![100u8, 100u8, 100u8];

assert_eq!(random_block.inner(), &vec![100u8, 100u8, 100u8]);

Trait Implementations§

Source§

impl Clone for RandomBlock

Source§

fn clone(&self) -> RandomBlock

Returns a duplicate 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 RandomBlock

Source§

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

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

impl Default for RandomBlock

Source§

fn default() -> RandomBlock

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

impl From<&Vec<u8>> for RandomBlock

§Convert &Vec to RandomBlock
use randomizer::RandomBlock;

let foo_vec = vec![100u8, 100u8, 100u8];

let random_block: RandomBlock = RandomBlock::from(&foo_vec);

assert_eq!(random_block.inner(), &foo_vec)
Source§

fn from(v: &Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<RandomBlock> for Result<String, Error>

§Convert RandomBlock into String

since its not possible to convert RandomBlock into a string by default this will convert the RandomBlock into a [‘Result<String, Error>’].

use randomizer::{RandomBlock,Error};

let foo_vec = vec![100u8, 100u8, 100u8];

let random_block: RandomBlock = RandomBlock::from(&foo_vec);
let string_res: Result<String, Error> = random_block.into();

assert_eq!(string_res.unwrap(), "ddd")
Source§

fn from(random_block: RandomBlock) -> Result<String, Error>

Converts to this type from the input type.
Source§

impl From<RandomBlock> for Result<Vec<u8>, Error>

Source§

fn from(r: RandomBlock) -> Self

Converts to this type from the input type.
Source§

impl From<RandomBlock> for Vec<u8>

Source§

fn from(r: RandomBlock) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for RandomBlock

§Convert Vec to RandomBlock
use randomizer::RandomBlock;

let foo_vec = vec![100u8, 100u8, 100u8];

let random_block: RandomBlock = foo_vec.clone().into();

assert_eq!(random_block.inner(), &foo_vec)
Source§

fn from(v: Vec<u8>) -> Self

Converts to this type from the input type.

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