audiofox 1.0.2

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

use std::fmt;
use std::str::FromStr;

use anyhow::anyhow;

use crate::common::result::{Error, Result};

/// Audio channels supported by Audiofox.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Channel {
    FL,
    FR,
}

impl FromStr for Channel {
    type Err = Error;

    fn from_str(s: &str) -> Result<Self> {
        match s {
            "FL" => Ok(Self::FL),
            "FR" => Ok(Self::FR),
            _ => Err(anyhow!("unsupported channel: {s}")),
        }
    }
}

impl fmt::Display for Channel {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::FL => write!(f, "FL"),
            Self::FR => write!(f, "FR"),
        }
    }
}

/// Port directions supported by Audiofox.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Direction {
    In,
    Out,
}

impl FromStr for Direction {
    type Err = Error;

    fn from_str(s: &str) -> Result<Self> {
        match s {
            "in" => Ok(Self::In),
            "out" => Ok(Self::Out),
            _ => Err(anyhow!("unsupported direction: {s}")),
        }
    }
}

impl fmt::Display for Direction {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::In => write!(f, "in"),
            Self::Out => write!(f, "out"),
        }
    }
}