Skip to main content

selene_core/
container.rs

1use std::path::Path;
2
3use crate::SUPPORTED_CONTAINERS;
4use serde::{Deserialize, Serialize};
5
6mod container_type_matcher;
7pub use container_type_matcher::*;
8
9mod trait_impls;
10
11/// All recognized audio containers
12#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Ord, Eq, Serialize, Deserialize)]
13pub enum ContainerFormat {
14    Flac,
15    Mp3,
16    Ogg,
17    Wav,
18}
19
20impl ContainerFormat {
21    /// Returns the name as of the container that ffmpeg uses for encoding (the "`format_name`")
22    #[must_use]
23    pub fn format_name(&self) -> &str {
24        match self {
25            ContainerFormat::Flac => "flac",
26            ContainerFormat::Mp3 => "mp3",
27            ContainerFormat::Ogg => "ogg",
28            ContainerFormat::Wav => "wav",
29        }
30    }
31
32    /// Returns true if the container is contained in [`SUPPORTED_CONTAINERS`]
33    #[must_use]
34    pub fn is_supported(&self) -> bool {
35        SUPPORTED_CONTAINERS.contains(self)
36    }
37
38    /// Wrapper around [`container_from_file()`]
39    ///
40    /// For more info, see [`container_from_file()`]
41    pub fn from_file(path: impl AsRef<Path>) -> Option<Self> {
42        container_from_file(path)
43    }
44}