apt_edsp/progress.rs
1use serde::{Deserialize, Serialize};
2
3/// The model describing a [`Progress` stanza].
4///
5/// [`Progress` stanza]: https://salsa.debian.org/apt-team/apt/-/blob/a8367745eac915281cc2b9fb98813e9225d1e55c/doc/external-dependency-solver-protocol.md#progress
6#[derive(Serialize, Deserialize, Debug, Default, Eq, PartialEq)]
7#[serde(rename_all = "PascalCase")]
8pub struct Progress {
9 /// Must contain a date and time timestamp from the UTC timezone, in RFC 2822 format.
10 pub progress: String,
11
12 /// An integer from 0 to 100, representing the completion of the dependency solving process,
13 /// as declared by the solver.
14 pub percentage: Option<String>,
15
16 /// A textual message, meant to be read by the APT user, describing what is going on
17 /// within the dependency solving process (e.g. the current phase of dependency solving,
18 /// as declared by the solver).
19 pub message: Option<String>,
20}
21
22impl Progress {
23 /// Writes this [`Progress`] to the given `writer`. On error, returns an [`ProgressWriteError`].
24 pub fn write_to(&self, writer: impl std::io::Write) -> Result<(), ProgressWriteError> {
25 rfc822_like::to_writer(writer, self).map_err(Into::into)
26 }
27}
28
29/// The error returned when [`Progress::write_to`] fails.
30///
31/// Though the implementation details are hidden, the struct implements [`std::error::Error`]
32/// and a human-friendly [`std::fmt::Display`] implementation.
33#[derive(Debug, thiserror::Error)]
34#[error(transparent)]
35pub struct ProgressWriteError(#[from] rfc822_like::ser::Error);