[−][src]Struct rand_pwd::RandPwd
struct RandPwd
Implementations
impl RandPwd
[src]
pub fn new<L, S, N>(ltr_cnt: L, sbl_cnt: S, num_cnt: N) -> Self where
L: ToBigUint,
S: ToBigUint,
N: ToBigUint,
[src]
L: ToBigUint,
S: ToBigUint,
N: ToBigUint,
Return an empty instance of RandPwd
Example
Basic usage:
use rand_pwd::RandPwd; use num_bigint::BigUint; let mut r_p = RandPwd::new(11, 4, 2); // If you want push a large number in it // parse the `&str` into `BigUint` use std::str::FromStr; let ltr_cnt = BigUint::from_str(&format!("{}000", usize::MAX)).unwrap(); let sbl_cnt = BigUint::from_str(&format!("{}000", usize::MAX)).unwrap(); let num_cnt = BigUint::from_str(&format!("{}000", usize::MAX)).unwrap(); r_p = RandPwd::new(ltr_cnt, sbl_cnt, num_cnt); // You can also mix the `BigUint` with primitive type
pub fn val(&self) -> &str
[src]
Return the content of random password in &str
Example
Basic usage:
use rand_pwd::RandPwd; let r_p = RandPwd::new(10, 2, 3); assert_eq!("", r_p.val())
pub fn set_val(&mut self, val: &str, op: &str)
[src]
Change the content of RandPwd
, depend on the name of operation you passed.
There's two operations: update and check
update means just replace the value you've passed and update the counts field
check means if the counts field of new value doesn't match the old one, it will panic! if checking passed, the old one will be replaced
Example
Basic usage:
// update use rand_pwd::RandPwd; use num_traits::ToPrimitive; let r_p = RandPwd::new(10, 2, 3); r_p.set_val("123456", "update"); assert_eq!(r_p.get_cnt("ltr").unwrap().to_usize().unwrap(), 0); assert_eq!(r_p.get_cnt("sbl").unwrap().to_usize().unwrap(), 0); assert_eq!(r_p.get_cnt("num").unwrap().to_usize().unwrap(), 6); // check use rand_pwd::RandPwd; let r_p = RandPwd::new(10, 2, 3); r_p.set_val("123456", "check"); // Will panic
pub fn unit(&self) -> usize
[src]
Return the value of UNIT
Example
Basic Usage:
use rand_pwd::RandPwd; let r_p = RandPwd::new(10, 2, 3); // The default value of unit is 1 assert_eq!(r_p.unit(), 1);
pub fn set_unit(&mut self, val: usize)
[src]
The value of UNIT is inversely proportional to memory overhead
In order to reduce the memory overhead, raise the value of UNIT
pub fn len(&self) -> usize
[src]
Returns the length of this RandPwd
, in both bytes and chars.
Example
Basic usage:
use rand_pwd::RandPwd;
pub fn is_empty(&self) -> bool
[src]
Returns true if this RandPwd
has a length of zero, and false otherwise.
pub fn get_cnt(&self, kind: &str) -> Option<&BigUint>
[src]
Get count of RandPwd
Example
Basic usage:
use rand_pwd::RandPwd; use num_traits::ToPrimitive; let r_p = RandPwd::new(10, 2, 3); assert_eq!(r_p.get_cnt("ltr").unwrap().to_usize().unwrap(), 10); assert_eq!(r_p.get_cnt("sbl").unwrap().to_usize().unwrap(), 2); assert_eq!(r_p.get_cnt("num").unwrap().to_usize().unwrap(), 3);
pub fn set_cnt<T: ToBigUint>(&mut self, kind: &str, val: T) -> Option<()>
[src]
Change the count of letters, symbols or numbers of RandPwd
Example
Basic usage:
use rand_pwd::*; let mut r_p = RandPwd::new(10, 2, 3); // Set the letter's count r_p.set_cnt("ltr", 0); r_p.join(); println!("{}", r_p.val()); // Output: *029( // Set the symbol's count r_p.set_cnt("sbl", 0); r_p.join(); println!("{}", r_p.val()); // Output: nz1MriAl0j5on // Set the number's count r_p.set_cnt("num", 0); r_p.join(); println!("{}", r_p.val()); // Output: +iQiQGSXl(nv
pub fn join(&mut self)
[src]
Generate the password for RandPwd
Example
Basic usage:
use rand_pwd::RandPwd; let mut r_p = RandPwd::new(10, 2, 3); r_p.join(); println!("{}", r_p);
Trait Implementations
impl Add<RandPwd> for RandPwd
[src]
type Output = Self
The resulting type after applying the +
operator.
fn add(self, rhs: Self) -> Self
[src]
impl AddAssign<RandPwd> for RandPwd
[src]
fn add_assign(&mut self, rhs: Self)
[src]
impl AsRef<str> for RandPwd
[src]
impl Clone for RandPwd
[src]
impl Debug for RandPwd
[src]
impl Default for RandPwd
[src]
impl Display for RandPwd
[src]
impl<'_> From<&'_ str> for RandPwd
[src]
Auto Trait Implementations
impl RefUnwindSafe for RandPwd
impl Send for RandPwd
impl Sync for RandPwd
impl Unpin for RandPwd
impl UnwindSafe for RandPwd
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToRandPwd for T where
T: AsRef<str>,
[src]
T: AsRef<str>,
fn to_randpwd(&Self) -> Option<RandPwd>
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,