Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SndFileError #6

Open
jazzyeagle opened this issue Mar 12, 2023 · 0 comments
Open

Update SndFileError #6

jazzyeagle opened this issue Mar 12, 2023 · 0 comments

Comments

@jazzyeagle
Copy link

I'm trying to work with loading the data into a vector in a struct I'm using. I'm attempting to use the following code for reading in the data:

pub fn load(&self, filename: &str) -> Result<(), sndfile::SndFileError> {
     let snd_file      = sndfile::OpenOptions::ReadOnly(sndfile::ReadOptions::Auto).from_path(filename)?;
     self.audioData    = snd_file.read_all_to_vec()?;
     self.sampleRate   = snd_file.get_samplerate();
     self.channelCount = snd_file.get_channels();
     self.format       = snd_file.get_major_format();

      Ok(())
}

The error comes with those "?" methods:

error[E0277]: `?` couldn't convert the error to `SndFileError`
  --> src/data/lup.rs:17:55
   |
17 |         self.audioData    = snd_file.read_all_to_vec()?;
   |                                                       ^ the trait `From<()>` is not implemented for `SndFileError`
   |
   = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
   = help: the following other types implement trait `FromResidual<R>`:
             <Result<T, F> as FromResidual<Result<Infallible, E>>>
             <Result<T, F> as FromResidual<Yeet<E>>>
   = note: required for `Result<(), SndFileError>` to implement `FromResidual<Result<Infallible, ()>>`

For more information about this error, try `rustc --explain E0277`.

SndFileError needs a few additional impl's to use the ? methods, notably std::fmt::Display, std::error::Error, and From<>. Since these ? methods are a nice way to write cleaner code, I thought it could be beneficial to have in your library.

At that point, I may even be able to refactor some of the other code for you as well. I'm working on a PR right now, which I may even have for you later today, but I wanted to make sure I logged the issue so you had an opportunity to review and respond, see if you agree with my proposed changes.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant