1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
pub extern crate sample;
#[cfg(feature="flac")]
pub extern crate claxon;
#[cfg(feature="wav")]
pub extern crate hound;
#[cfg(feature="ogg_vorbis")]
pub extern crate lewton;
#[cfg(feature="caf")]
pub extern crate caf;
#[cfg(feature="alac")]
pub extern crate alac;
#[cfg(feature="caf_alac")]
mod caf_alac;
pub mod read;
pub mod write;
pub use read::{open, Reader};
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
pub enum Format {
#[cfg(feature="flac")]
Flac,
#[cfg(feature="ogg_vorbis")]
OggVorbis,
#[cfg(feature="wav")]
Wav,
#[cfg(feature="caf_alac")]
CafAlac,
}
impl Format {
pub fn from_extension(extension: &str) -> Option<Self> {
match extension {
#[cfg(feature="flac")]
"flac" => Some(Format::Flac),
#[cfg(feature="ogg_vorbis")]
"ogg" | "oga" => Some(Format::OggVorbis),
#[cfg(feature="wav")]
"wav" | "wave" => Some(Format::Wav),
#[cfg(feature="caf")]
"caf" => Some(Format::CafAlac),
_ => None,
}
}
pub fn extension(&self) -> &'static str {
match *self {
#[cfg(feature="flac")]
Format::Flac => "flac",
#[cfg(feature="wav")]
Format::Wav => "wav",
#[cfg(feature="ogg_vorbis")]
Format::OggVorbis => "ogg",
#[cfg(feature="caf_alac")]
Format::CafAlac => "caf",
}
}
}