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

Vec<Vec<T>> #671

Open
Timmmm opened this issue Jan 13, 2021 · 2 comments
Open

Vec<Vec<T>> #671

Timmmm opened this issue Jan 13, 2021 · 2 comments

Comments

@Timmmm
Copy link

Timmmm commented Jan 13, 2021

Sorry for the deluge of questions! Is it possible to return Vec<Vec<SomeStruct>> from a bridge function? It says the inner Vec is not a supported type. We've tried various things (currently resorting to a single-field struct which kind of sucks).

@dtolnay
Copy link
Owner

dtolnay commented Jan 13, 2021

You can wrap either the outer or inner vec in a struct. Inner vec (probably what you found):

#[cxx::bridge]
mod ffi {
    struct VecT {
        vec: Vec<T>,
    }
    extern "Rust" {
        type T;
        fn f() -> Vec<VecT>;
    }
}

Outer vec, which may be more convenient depending on what this is interacting with on the Rust side:

struct VecVecT {
    vec: Vec<Vec<T>>,
}

#[cxx::bridge]
mod ffi {
    extern "Rust" {
        type T;
        type VecVecT;
        fn get(&self, i: usize) -> &Vec<T>;

        fn f() -> Box<VecVecT>;
    }
}

@Timmmm
Copy link
Author

Timmmm commented Jan 14, 2021

Ah wrapping the outer Vec is nicer but we need to be able to access the contents from C++ unfortunately. I presume supporting Vec<Vec<>> and other nested types isn't really hard, it just hasn't been done yet?

Thanks for all the help!

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

2 participants