podman_api/
lib.rs

1//! Rust interface to Podman.
2#![cfg_attr(docsrs, feature(doc_cfg))]
3
4#[macro_use]
5mod builder;
6mod podman;
7
8pub mod api;
9pub mod models;
10pub mod opts;
11
12/// Connection related items.
13pub mod conn {
14    pub(crate) use containers_api::conn::*;
15    pub use containers_api::conn::{Error, Multiplexer, TtyChunk};
16}
17
18pub use containers_api::id::Id;
19pub use containers_api::version::{ApiVersion, Error as VersionError};
20pub use podman::Podman;
21
22/// Latest libpod API version supported by this crate
23pub const LATEST_API_VERSION: ApiVersion = ApiVersion::new(4, Some(3), Some(1));
24macro_rules! _version {
25    () => {
26        "v4.3.1"
27    };
28}
29pub(crate) use _version as version;
30
31/// Common result type used throughout this crate
32pub type Result<T> = std::result::Result<T, Error>;
33
34// common crate imports
35pub(crate) use futures_util::stream::{Stream, TryStreamExt};
36pub(crate) use serde_json::Value;
37
38use containers_api::conn::hyper::StatusCode;
39use futures_util::io::Error as IoError;
40use serde_json::Error as SerdeError;
41use thiserror::Error as ThisError;
42
43#[derive(Debug, ThisError)]
44/// Common error type for all functions of this library
45pub enum Error {
46    #[error(transparent)]
47    SerdeJsonError(#[from] SerdeError),
48    #[error(transparent)]
49    #[allow(clippy::upper_case_acronyms)]
50    IO(#[from] IoError),
51    #[error("The response is invalid - {0}")]
52    InvalidResponse(String),
53    #[error("error {code} - {message}")]
54    Fault { code: StatusCode, message: String },
55    #[error("Provided scheme `{0}` is not supported")]
56    UnsupportedScheme(String),
57    #[error("Provided URI is missing authority part after scheme")]
58    MissingAuthority,
59    #[error("Failed to parse url - {0}")]
60    InvalidUrl(url::ParseError),
61    #[error("Invalid port - {0}")]
62    InvalidPort(String),
63    #[error("Invalid protocol - {0}")]
64    InvalidProtocol(String),
65    #[error("Failed to serialize opts - {0}")]
66    OptsSerialization(String),
67    #[error(transparent)]
68    Error(#[from] containers_api::conn::Error),
69    #[error("{0}")]
70    StringError(String),
71    #[error(transparent)]
72    ServerError(#[from] models::JsonError),
73    #[error("Cannot start an unchecked exec instance")]
74    UncheckedExec,
75}
76
77impl Clone for Error {
78    fn clone(&self) -> Self {
79        match self {
80            Error::SerdeJsonError(err) => Error::StringError(err.to_string()),
81            Error::IO(err) => Error::StringError(err.to_string()),
82            Error::Error(err) => Error::StringError(err.to_string()),
83            e => e.clone(),
84        }
85    }
86}