apt_parse/
defs.rs

1// SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net>
2// SPDX-License-Identifier: BSD-2-Clause
3//! Common definitions for the `apt-parse` crate.
4
5use anyhow::Error as AnyError;
6use thiserror::Error;
7
8/// An error that occurred during the doing of things.
9#[derive(Debug, Error)]
10#[non_exhaustive]
11#[allow(clippy::error_impl_error)]
12pub enum Error {
13    /// Something went really, really wrong.
14    #[error("apt-parse internal error")]
15    InternalError(#[source] AnyError),
16
17    /// Some known missing functionality.
18    #[error("Not implemented yet: {0}")]
19    NotImplemented(String),
20
21    /// Could not parse the output of `apt-cache policy`.
22    #[error("Could not parse the output of `apt-cache policy`")]
23    ParsePolicy(#[source] AnyError),
24}
25
26/// Runtime configuration for the `apt-parse` routines.
27#[derive(Debug, Default)]
28pub struct Config {
29    /// Verbose operation; display diagnostic output.
30    verbose: bool,
31}
32
33impl Config {
34    /// Verbose operation; display diagnostic output.
35    #[inline]
36    #[must_use]
37    pub const fn verbose(&self) -> bool {
38        self.verbose
39    }
40
41    /// Return a new [`Config`] object with the specified verbosity level.
42    #[inline]
43    #[must_use]
44    pub const fn with_verbose(self, verbose: bool) -> Self {
45        Self { verbose }
46    }
47}