[][src]Struct iota_pow::PearlDiver

pub struct PearlDiver { /* fields omitted */ }

The PearlDiver struct allows you to start, stop, and check in on PoW while its working

 use iota_pow::{PearlDiver, PowOptions};
 use iota_crypto::{Curl, Sponge};
 use rand::{thread_rng, Rng};

 const HASH_SIZE: usize = 243;
 const MIN_WEIGHT_MAGNITUDE: usize = 9;

 let mut rng = thread_rng();
 let mut curl = Curl::default();
 let trits: Vec<i8> = (0..8019).map(|_| rng.gen_range(-1, 2)).collect();
 let mut pearl_diver = PearlDiver::default();
 let result_trits = pearl_diver
     .search(trits, PowOptions{min_weight_magnitude: 9, ..PowOptions::default()})
     .unwrap();
 let mut hash_trits = [0; HASH_SIZE];
 curl.reset();
 curl.absorb(&result_trits).unwrap();
 curl.squeeze(&mut hash_trits).unwrap();
 for j in (HASH_SIZE - MIN_WEIGHT_MAGNITUDE..HASH_SIZE - 1).rev() {
     assert_eq!(hash_trits[j], 0);
 }

Methods

impl PearlDiver[src]

pub fn new() -> PearlDiver[src]

Creates a new PearlDiver instance

pub fn cancel(&mut self)[src]

If you have multiple references to the same PearlDriver, this will allow you to cancel the proof of work. For this to be useful, you'll probably need to wrap the PearlDiver in an Arc

 use iota_pow::PearlDiver;
 let mut pearl_diver = PearlDiver::new();
 // ... start running a pearl diver on another thread ...
 pearl_diver.cancel();

pub fn status(&self) -> PearlDiverState[src]

Returns the current status of PoW.

pub fn search(
    &mut self,
    input: impl Trinary,
    options: PowOptions
) -> Result<Vec<Trit>, Error>
[src]

Performs proof of work in place

  • input - Anything implementing the Trinary trait
  • options - PoW options

Trait Implementations

impl Default for PearlDiver[src]

impl Debug for PearlDiver[src]

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]