Skip to main content

AnalysisProgress

Struct AnalysisProgress 

Source
pub struct AnalysisProgress<W: WarningHandling = WarningsAsErrors> { /* private fields */ }
Expand description

An in-progress analysis operation for a single position.

Implementations§

Source§

impl<W: WarningHandling> AnalysisProgress<W>

Source

pub async fn finish(self) -> WarningResult<Option<AnalysisResult>, W>

Waits for the analysis to finish and returns the result.

If the analysis was terminated before any search was performed, returns Ok(None).

Source

pub async fn poll( self, ) -> ControlFlow<WarningResult<Option<AnalysisResult>, W>, Self>

Waits for an analysis update.

This is mainly useful when using AnalysisRequest::report_during_search_every. Otherwise, it’s simpler to just call finish to wait for the final result.

If the analysis is finished, it consumes this object and returns ControlFlow::Break containing the final result. If a partial result is available, it returns ControlFlow::Continue containing this object again, which can be read using read or polled again for the next update.

This method (in combination with read) is conceptually similar to Tokio’s watch channel. It provides a way to follow the latest information as it becomes available without any danger of falling behind.

§Example
loop {
    match progress.poll().await {
        ControlFlow::Break(result) => {
            match result {
                Ok(Some(result)) => {
                    println!("Winrate: {:.1}%", result.root_info.winrate * 100.0);
                }
                Ok(None) => println!("No results"),
                Err(e) => println!("Error: {e}"),
            }
            break;
        }
        ControlFlow::Continue(p) => {
            progress = p;
            if let Ok(Some(result)) = progress.read().await.as_ref() {
                println!(
                    "Winrate: {:.1}% Visits: {}",
                    result.root_info.winrate * 100.0,
                    result.root_info.visits
                );
            }
        }
    };
}
Source

pub async fn read( &self, ) -> RwLockReadGuard<'_, WarningResult<Option<AnalysisResult>, W>>

Reads the latest analysis result available.

See also: poll

Trait Implementations§

Source§

impl<W: WarningHandling> Debug for AnalysisProgress<W>

Source§

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

Formats the value using the given formatter. Read more

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