Skip to content

Can't pass a std::vector<int> #422

@scullionw

Description

@scullionw

Expected Behavior

I can pass std::vector<int32_t>, but the the c++ library I want to use uses int, not int32_t

std::vector<int> build_array() {
    auto values = std::vector<int> {1,2,3,4,5};
    for (auto& v: values) v = v * 2;
    return values;
}

Not sure how to get around this since I can't impl VectorElement for c_int due to the orphan rule? There must be something easy I'm missing..

Actual Behavior

   Compiling autoprint v0.1.0 (/Users/scullionw/Projects/autoprint)
error[E0277]: the trait bound `autocxx::c_int: VectorElement` is not satisfied
  --> /Users/scullionw/Projects/autoprint/include-rs/12075411190909706338.rs:1:2988
   |
1  | ...xx_wrapper () -> UniquePtr < CxxVector < c_int > > ; type c_int = autocxx :: c_int ; include ! ("wrapper/wrapper.h") ; include ! ("aut...
   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `VectorElement` is not implemented for `autocxx::c_int`
   |
  ::: /Users/scullionw/.cargo/registry/src/github.com-1ecc6299db9ec823/cxx-1.0.46/src/unique_ptr.rs:18:8
   |
18 |     T: UniquePtrTarget,
   |        --------------- required by this bound in `UniquePtr`
   |
   = note: required because of the requirements on the impl of `UniquePtrTarget` for `CxxVector<autocxx::c_int>`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
error: could not compile `autoprint`

To learn more, run the command again with --verbose.

Specifications

  • Version: autocxx = "0.6.0" cxx = "1.0.46" rustc 1.53.0-nightly
  • Platform: macOS 11.2.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions