selene-core 0.3.0

selene-core is the backend for Selene, a local-first music player
Documentation
use std::path::Path;

use crate::SUPPORTED_CONTAINERS;
use serde::{Deserialize, Serialize};

mod container_type_matcher;
pub use container_type_matcher::*;

mod trait_impls;

/// All recognized audio containers
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Ord, Eq, Serialize, Deserialize)]
pub enum ContainerFormat {
    Flac,
    Mp3,
    Ogg,
    Wav,
}

impl ContainerFormat {
    /// Returns the name as of the container that ffmpeg uses for encoding (the "`format_name`")
    #[must_use]
    pub fn format_name(&self) -> &str {
        match self {
            ContainerFormat::Flac => "flac",
            ContainerFormat::Mp3 => "mp3",
            ContainerFormat::Ogg => "ogg",
            ContainerFormat::Wav => "wav",
        }
    }

    /// Returns true if the container is contained in [`SUPPORTED_CONTAINERS`]
    #[must_use]
    pub fn is_supported(&self) -> bool {
        SUPPORTED_CONTAINERS.contains(self)
    }

    /// Wrapper around [`container_from_file()`]
    ///
    /// For more info, see [`container_from_file()`]
    pub fn from_file(path: impl AsRef<Path>) -> Option<Self> {
        container_from_file(path)
    }
}