yield_progress/
info.rs

1use core::panic::Location;
2
3/// Information available to a progress callback.
4pub struct ProgressInfo<'a> {
5    pub(crate) fraction: f32,
6    pub(crate) label: Option<&'a crate::Label>,
7    pub(crate) location: &'a Location<'a>,
8}
9impl<'a> ProgressInfo<'a> {
10    /// The fraction of overall progress that has been made; always at least 0 and at most 1.
11    ///
12    /// The value might be less than previously reported values; for example, if the
13    /// amount of remaining work is only estimated and the estimate has changed.
14    pub fn fraction(&self) -> f32 {
15        self.fraction
16    }
17
18    /// A label for the current portion of work.
19    pub fn label_str(&self) -> &str {
20        // This function is called `label_str()`, and does not return`&'a str`, to leave room for a
21        // non-string label being offered as a non-breaking change.
22        self.label.map_or("", |label_rc| &**label_rc)
23    }
24
25    /// Source code location which reported the progress.
26    pub fn location(&self) -> &'a Location<'a> {
27        self.location
28    }
29}
30
31/// Information available to a yield callback.
32pub struct YieldInfo<'a> {
33    pub(crate) location: &'a Location<'a>,
34}
35
36impl<'a> YieldInfo<'a> {
37    /// Source code location which yielded.
38    pub fn location(&self) -> &'a Location<'a> {
39        self.location
40    }
41}