pub trait Decoder {
// Required method
fn decode(&self, path: &Path) -> AnalysisResult<ResampledAudio>;
// Provided methods
fn analyze_path<P: AsRef<Path>>(&self, path: P) -> AnalysisResult<Analysis> { ... }
fn analyze_paths<P: Into<PathBuf>, F: IntoIterator<Item = P>>(
&self,
paths: F,
) -> IntoIter<(PathBuf, AnalysisResult<Analysis>)>
where Self: Sync + Send { ... }
fn analyze_paths_with_cores<P: Into<PathBuf>, F: IntoIterator<Item = P>>(
&self,
paths: F,
number_cores: NonZeroUsize,
) -> IntoIter<(PathBuf, AnalysisResult<Analysis>)>
where Self: Sync + Send { ... }
fn analyze_path_with_callback<P: AsRef<Path>>(
&self,
path: P,
callback: Sender<(P, AnalysisResult<Analysis>)>,
) -> Result<(), SendError<()>> { ... }
fn analyze_paths_with_callback<P: Into<PathBuf>, I: Send + IntoIterator<Item = P>>(
&self,
paths: I,
callback: Sender<(PathBuf, AnalysisResult<Analysis>)>,
) -> Result<(), SendError<()>>
where Self: Sync + Send { ... }
fn analyze_paths_with_cores_with_callback<P: Into<PathBuf>, I: IntoIterator<Item = P>>(
&self,
paths: I,
number_cores: NonZeroUsize,
callback: Sender<(PathBuf, AnalysisResult<Analysis>)>,
) -> Result<(), SendError<()>>
where Self: Sync + Send { ... }
}Expand description
Trait used to implement your own decoder.
The decode function should be implemented so that it
decodes and resample a song to one channel with a sampling rate of 22050 Hz
and a f32le layout.
Once it is implemented, several functions
to perform analysis from path(s) are available, such as
song_from_path and
analyze_paths.
Required Methods§
Sourcefn decode(&self, path: &Path) -> AnalysisResult<ResampledAudio>
fn decode(&self, path: &Path) -> AnalysisResult<ResampledAudio>
A function that should decode and resample a song, optionally extracting the song’s metadata such as the artist, the album, etc.
The output sample array should be resampled to f32le, one channel, with a sampling rate of 22050 Hz. Anything other than that will yield wrong results.
§Errors
This function will return an error if the file path is invalid, if the file path points to a file containing no or corrupted audio stream, or if the analysis could not be conducted to the end for some reason.
The error type returned should give a hint as to whether it was a decoding or an analysis error.
Provided Methods§
Sourcefn analyze_path<P: AsRef<Path>>(&self, path: P) -> AnalysisResult<Analysis>
fn analyze_path<P: AsRef<Path>>(&self, path: P) -> AnalysisResult<Analysis>
Returns a decoded song’s Analysis given a file path, or an error if the song
could not be analyzed for some reason.
§Arguments
path- APathholding a valid file path to a valid audio file.
§Errors
This function will return an error if the file path is invalid, if the file path points to a file containing no or corrupted audio stream, or if the analysis could not be conducted to the end for some reason.
The error type returned should give a hint as to whether it was a decoding or an analysis error.
Sourcefn analyze_paths<P: Into<PathBuf>, F: IntoIterator<Item = P>>(
&self,
paths: F,
) -> IntoIter<(PathBuf, AnalysisResult<Analysis>)>
fn analyze_paths<P: Into<PathBuf>, F: IntoIterator<Item = P>>( &self, paths: F, ) -> IntoIter<(PathBuf, AnalysisResult<Analysis>)>
Analyze songs in paths, and return the Analysis objects through an
mpsc::IntoIter.
Returns an iterator, whose items are a tuple made of
the song path (to display to the user in case the analysis failed),
and a Result<Analysis>.
Sourcefn analyze_paths_with_cores<P: Into<PathBuf>, F: IntoIterator<Item = P>>(
&self,
paths: F,
number_cores: NonZeroUsize,
) -> IntoIter<(PathBuf, AnalysisResult<Analysis>)>
fn analyze_paths_with_cores<P: Into<PathBuf>, F: IntoIterator<Item = P>>( &self, paths: F, number_cores: NonZeroUsize, ) -> IntoIter<(PathBuf, AnalysisResult<Analysis>)>
Analyze songs in paths, and return the Analysis objects through an
mpsc::IntoIter. number_cores sets the number of cores the analysis
will use, capped by your system’s capacity. Most of the time, you want to
use the simpler analyze_paths functions, which autodetects the number
of cores in your system.
Return an iterator, whose items are a tuple made of
the song path (to display to the user in case the analysis failed),
and a Result<Analysis>.
Sourcefn analyze_path_with_callback<P: AsRef<Path>>(
&self,
path: P,
callback: Sender<(P, AnalysisResult<Analysis>)>,
) -> Result<(), SendError<()>>
fn analyze_path_with_callback<P: AsRef<Path>>( &self, path: P, callback: Sender<(P, AnalysisResult<Analysis>)>, ) -> Result<(), SendError<()>>
Returns a decoded song’s Analysis given a file path, or an error if the song
could not be analyzed for some reason.
§Arguments
path- APathholding a valid file path to a valid audio file.callback- A function that will be called with the path and the result of the analysis.
§Errors
Errors if the callback channel is closed.
Sourcefn analyze_paths_with_callback<P: Into<PathBuf>, I: Send + IntoIterator<Item = P>>(
&self,
paths: I,
callback: Sender<(PathBuf, AnalysisResult<Analysis>)>,
) -> Result<(), SendError<()>>
fn analyze_paths_with_callback<P: Into<PathBuf>, I: Send + IntoIterator<Item = P>>( &self, paths: I, callback: Sender<(PathBuf, AnalysisResult<Analysis>)>, ) -> Result<(), SendError<()>>
Analyze songs in paths, and return the Analysis objects through an
mpsc::IntoIter.
Returns an iterator, whose items are a tuple made of
the song path (to display to the user in case the analysis failed),
and a Result<Analysis>.
You can cancel the job by dropping the callback channel.
§Errors
Errors if the callback channel is closed.
Sourcefn analyze_paths_with_cores_with_callback<P: Into<PathBuf>, I: IntoIterator<Item = P>>(
&self,
paths: I,
number_cores: NonZeroUsize,
callback: Sender<(PathBuf, AnalysisResult<Analysis>)>,
) -> Result<(), SendError<()>>
fn analyze_paths_with_cores_with_callback<P: Into<PathBuf>, I: IntoIterator<Item = P>>( &self, paths: I, number_cores: NonZeroUsize, callback: Sender<(PathBuf, AnalysisResult<Analysis>)>, ) -> Result<(), SendError<()>>
Analyze songs in paths, and return the Analysis objects through an
mpsc::IntoIter. number_cores sets the number of cores the analysis
will use, capped by your system’s capacity. Most of the time, you want to
use the simpler analyze_paths_with_callback functions, which autodetects the number
of cores in your system.
Return an iterator, whose items are a tuple made of
the song path (to display to the user in case the analysis failed),
and a Result<Analysis>.
You can cancel the job by dropping the callback channel.
§Errors
Errors if the callback channel is closed.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.