Import in separate crate and change source ID calculation

This commit is contained in:
Elias Projahn 2021-02-20 19:03:26 +01:00
parent c2c811e321
commit aeb7da73c9
20 changed files with 479 additions and 379 deletions

96
import/src/error.rs Normal file
View file

@ -0,0 +1,96 @@
use std::error;
/// An error within an import session.
#[derive(thiserror::Error, Debug)]
pub enum Error {
/// A timeout was reached.
#[error("{0}")]
Timeout(String),
/// Some common error.
#[error("{msg}")]
Other {
/// The error message.
msg: String,
#[source]
source: Option<Box<dyn error::Error + Send + Sync>>,
},
/// Something unexpected happened.
#[error("{msg}")]
Unexpected {
/// The error message.
msg: String,
#[source]
source: Option<Box<dyn error::Error + Send + Sync>>,
},
}
impl Error {
/// Create a new error without an explicit source.
pub(super) fn o(msg: String) -> Self {
Self::Unexpected {
msg,
source: None,
}
}
/// Create a new error with an explicit source.
pub(super) fn os(source: impl error::Error + Send + Sync + 'static) -> Self {
Self::Unexpected {
msg: format!("An error has happened: {}", source),
source: Some(Box::new(source)),
}
}
/// Create a new unexpected error without an explicit source.
pub(super) fn u(msg: String) -> Self {
Self::Unexpected {
msg,
source: None,
}
}
/// Create a new unexpected error with an explicit source.
pub(super) fn us(source: impl error::Error + Send + Sync + 'static) -> Self {
Self::Unexpected {
msg: format!("An unexpected error has happened: {}", source),
source: Some(Box::new(source)),
}
}
}
impl From<futures_channel::oneshot::Canceled> for Error {
fn from(err: futures_channel::oneshot::Canceled) -> Self {
Self::us(err)
}
}
impl From<gstreamer::glib::Error> for Error {
fn from(err: gstreamer::glib::Error) -> Self {
Self::us(err)
}
}
impl From<gstreamer::glib::BoolError> for Error {
fn from(err: gstreamer::glib::BoolError) -> Self {
Self::us(err)
}
}
impl From<gstreamer::StateChangeError> for Error {
fn from(err: gstreamer::StateChangeError) -> Self {
Self::us(err)
}
}
impl From<std::io::Error> for Error {
fn from(err: std::io::Error) -> Self {
Self::us(err)
}
}
pub type Result<T> = std::result::Result<T, Error>;