Skip to main content

ProgressReporter

Struct ProgressReporter 

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

A throttled sink for pipeline progress.

Pass Some(&reporter) to a *_with_progress entry point; the reporter may be shared across threads and outlive the call.

§Example

use manifold_rust::progress::ProgressReporter;
use manifold_rust::manifold::Manifold;
use manifold_rust::linalg::Vec3;
use manifold_rust::types::{BooleanEngine, OpType};
use std::sync::{Arc, Mutex};

let seen = Arc::new(Mutex::new(Vec::new()));
let sink = Arc::clone(&seen);
let reporter = ProgressReporter::new(move |phase, fraction| {
    sink.lock().unwrap().push((phase.name(), fraction));
});

let a = Manifold::cube(Vec3::splat(1.0), true);
let b = Manifold::sphere(0.6, 16);
let out = a.boolean_with_engine_and_progress(
    &b, OpType::Add, BooleanEngine::Robust, None, Some(&reporter),
);
assert!(out.volume() > 0.0);
assert!(!seen.lock().unwrap().is_empty());

Implementations§

Source§

impl ProgressReporter

Source

pub fn new<F>(callback: F) -> Self
where F: Fn(Phase, Option<f64>) + Send + Sync + 'static,

Source

pub fn begin_phase(&self, phase: Phase, total: u64)

Enter phase, expecting total work items (0 = no total known, which reports as an indeterminate phase). Always emits a callback, so a phase transition is never throttled away.

Source

pub fn advance(&self, n: u64)

Record n completed work items in the current phase, emitting a callback only when the throttle threshold is crossed.

Safe to call from several threads at once; the counter is atomic and the callback is serialized. Under contention two threads can both cross the threshold and both report, which is harmless — this is a UI hint, not a ledger.

Trait Implementations§

Source§

impl Debug for ProgressReporter

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.