[−][src]Struct iota_pow::PearlDiver
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]
&mut self,
input: impl Trinary,
options: PowOptions
) -> Result<Vec<Trit>, Error>
Performs proof of work in place
input
- Anything implementing the Trinary traitoptions
- PoW options
Trait Implementations
impl Default for PearlDiver
[src]
impl Debug for PearlDiver
[src]
Auto Trait Implementations
impl Send for PearlDiver
impl Sync for PearlDiver
impl Unpin for PearlDiver
impl UnwindSafe for PearlDiver
impl RefUnwindSafe for PearlDiver
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
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<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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,