ronniec95 / xladd-derive

Macros to help write Excel User defined functions easily in Rust
MIT License
18 stars 1 forks source link

Trying to run the example, and get "Array2 does not implement "From<&Variant>"" #10

Open dorianmeric opened 1 year ago

dorianmeric commented 1 year ago

Hi @ronniec95, I'm trying to use your library to build an Excel addin that will have a function that takes a 2d array of cells, and that also outputs a 2d array of values into the spreadsheet. The Readme seems to indicate that you have tried making this a possibility.

I copy-paste the code from the example in "example/train.rs" into a new project (into the file src/lib.rs), however the example does not compile for me, as I get the following error message:

From Rust-analyzer:

[E0277] the trait bound `ArrayBase<OwnedRepr<String>, Dim<[usize; 2]>>: From<&Variant>` is not satisfied. 
[Note] the trait `From<&Variant>` is not implemented for `ArrayBase<OwnedRepr<String>, Dim<[usize; 2]>>`

Full error from the compiler:

   Compiling xl-stress-loss v0.1.0 (F:\Creations\code\rust\xl-stress-loss)
error[E0277]: the trait bound `ArrayBase<OwnedRepr<String>, Dim<[usize; 2]>>: From<&Variant>` is not satisfied
  --> src\lib.rs:45:1
   |
45 | #[xl_func(category = "OptionPricing", prefix = "my", rename = "bar")]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<&Variant>` is not implemented for `ArrayBase<OwnedRepr<String>, Dim<[usize; 2]>>`
   |
   = help: the following other types implement trait `From<T>`:
             <ArrayBase<CowRepr<'a, A>, D> as From<&'a ArrayBase<S, D>>>
             <ArrayBase<CowRepr<'a, A>, D> as From<ArrayBase<OwnedRepr<A>, D>>>
             <ArrayBase<CowRepr<'a, A>, D> as From<ArrayBase<ViewRepr<&'a A>, D>>>
             <ArrayBase<CowRepr<'a, A>, Dim<[usize; 1]>> as From<&'a Slice>>
             <ArrayBase<OwnedArcRepr<A>, D> as From<ArrayBase<OwnedRepr<A>, D>>>
             <ArrayBase<OwnedRepr<A>, Dim<[usize; 2]>> as From<Vec<V>>>
             <ArrayBase<OwnedRepr<A>, Dim<[usize; 3]>> as From<Vec<V>>>
             <ArrayBase<S, Dim<[usize; 1]>> as From<Box<[A]>>>
           and 5 others
   = note: required for `&Variant` to implement `Into<ArrayBase<OwnedRepr<String>, Dim<[usize; 2]>>>`
   = note: required for `ArrayBase<OwnedRepr<String>, Dim<[usize; 2]>>` to implement `TryFrom<&Variant>`
   = note: this error originates in the attribute macro `xl_func` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `Variant: From<ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>>` is not satisfied
  --> src\lib.rs:45:1
   |
45 | #[xl_func(category = "OptionPricing", prefix = "my", rename = "bar")]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>>` is not implemented for `Variant`
   |
   = help: the following other types implement trait `From<T>`:
             <Variant as From<&(&[&str], usize)>>
             <Variant as From<&(&[f64], usize)>>
             <Variant as From<&str>>
             <Variant as From<*mut xloper12>>
             <Variant as From<String>>
             <Variant as From<Vec<&str>>>
             <Variant as From<Vec<(String, f64)>>>
             <Variant as From<Vec<(Variant, f64)>>>
           and 7 others
   = note: this error originates in the attribute macro `xl_func` (in Nightly builds, run with -Z macro-backtrace for more info)

Any clue what is wrong?

Thanks

dorianmeric commented 1 year ago

I think it's to do with the version of ndarray. I had added the latest version via "cargo add ndarray", which was v0.15.2

If I change it, in my Cargo.toml file, to v0.14 then the error disappears.

[lib]
crate-type = ["cdylib"]

[dependencies]
log = "0.4.17"
ndarray = {version = "^0.14"}      ## THIS VERSION SHOULD NOT BE 0.15.2
xladd = {git="https://github.com/ronniec95/xladd", features=["use_ndarray"] }
xladd-derive = "0.7.0"

then the error disappears.

ronniec95 commented 1 year ago

Thanks for the heads up. I'll look at updating to latest ndarray.

On Mon, 16 Jan 2023, 03:39 Dorian Meric, @.***> wrote:

I think it's to do with the version of ndarray. I had added the latest version via "cargo add ndarray", which was v0.15.2

If I change it, in my Cargo.toml file, to v0.14 then the error disappears.

[lib] crate-type = ["cdylib"]

[dependencies] log = "0.4.17" ndarray = {version = "^0.14"} ## THIS VERSION SHOULD NOT BE 0.15.2 xladd = {git="https://github.com/ronniec95/xladd", features=["use_ndarray"] } xladd-derive = "0.7.0"

then the error disappears.

— Reply to this email directly, view it on GitHub https://github.com/ronniec95/xladd-derive/issues/10#issuecomment-1383434749, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGY5WCAJYTJ473YZQ2T3ALWSS7ITANCNFSM6AAAAAAT4HPSMU . You are receiving this because you were mentioned.Message ID: @.***>