audiofox 1.0.1

Cross platform audio capture made easy!
// SPDX-License-Identifier: GPL-2.0-or-later WITH Classpath-exception-2.0
// Audiofox, the audio capturer!
// Copyright (c) 2026 foxberries

// Levels are currently only used on Linux, but work on all platforms
#![allow(unused)]

/// The standard error type of the Audiofox library, which wraps [`anyhow`] for backtraces and error
/// context. You do not need to import `anyhow` to receive this functionality.
pub type Error = anyhow::Error;
/// The standard return type of the Audiofox library.
pub type Result<T> = core::result::Result<T, Error>;

/// An [`Error`] associated with the [`log::Level`] at which it should be logged.
#[derive(Debug)]
pub struct LeveledError {
    pub error: Error,
    pub level: log::Level,
}

/// A shorthand for <code>Result<T, [LeveledError]></code>.
pub type LeveledResult<T> = core::result::Result<T, LeveledError>;

pub trait Level<T> {
    /// Attach a log level to a `Result`.
    fn level(self, level: log::Level) -> LeveledResult<T>;
}

impl<T> Level<T> for Result<T> {
    fn level(self, level: log::Level) -> LeveledResult<T> {
        self.map_err(|error| LeveledError { error, level })
    }
}