Xeiron / sndfile.rs

A safe rust wrapper of libsndfile
MIT License
10 stars 7 forks source link

README example does not compile #9

Closed nils-werner closed 1 year ago

nils-werner commented 1 year ago

I'm trying to compile the README example, but I'm stubling across this error during compilation, and I'm not familiar enough with Rust to understand what exactly is going wrong. snd.read_all_to_ndarray().unwrap() returns an ArrayBase<OwnedRepr<_>, Dim<[usize; 2]>> instead of an ArrayBase<OwnedRepr<f32>, Dim<[usize; 2]>>, but I'm not sure why the compiler can't pick the right impl for this...

error[E0308]: mismatched types
    --> src/main.rs:9:36
     |
9    |   let data: ndarray::Array2<f32> = snd.read_all_to_ndarray().unwrap();
     |             --------------------   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `ArrayBase<OwnedRepr<f32>, Dim<[usize; 2]>>`, found `ArrayBase<OwnedRepr<_>, Dim<[usize; 2]>>`
     |             |
     |             expected due to this
     |
     = note: `ArrayBase<OwnedRepr<_>, Dim<[usize; 2]>>` and `ArrayBase<OwnedRepr<f32>, Dim<[usize; 2]>>` have similar names, but are actually distinct types
note: `ArrayBase<OwnedRepr<_>, Dim<[usize; 2]>>` is defined in crate `ndarray`
    --> /home/nils/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ndarray-0.13.1/src/lib.rs:1221:1
     |
1221 | pub struct ArrayBase<S, D>
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^
note: `ArrayBase<OwnedRepr<f32>, Dim<[usize; 2]>>` is defined in crate `ndarray`
    --> /home/nils/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ndarray-0.15.6/src/lib.rs:1268:1
     |
1268 | pub struct ArrayBase<S, D>
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^
     = note: perhaps two different versions of crate `ndarray` are being used?

For more information about this error, try `rustc --explain E0308`.
error: could not compile `dsptest` (bin "dsptest") due to previous error

I'm running

rustc 1.71.0 (8ede3aae2 2023-07-12)
cargo 1.71.0 (cfd3bbd8f 2023-06-08)
ndarray v0.15.6
sndfile v0.1.1
nils-werner commented 1 year ago

Actually, the reason is that I have two different versions of ndarray installed:

├── ndarray v0.15.6
└── sndfile v0.1.1
    └── ndarray v0.13.1

I had to restrict the outer ndarray to a version compatible to 0.13, so that cargo could match the two:

cargo add ndarray@^0.13