Skip to content

Is it possible to use foreign types? #16

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

Closed
porky11 opened this issue Aug 6, 2017 · 5 comments
Closed

Is it possible to use foreign types? #16

porky11 opened this issue Aug 6, 2017 · 5 comments

Comments

@porky11
Copy link

porky11 commented Aug 6, 2017

Is it, or will it be possible to use types from c++? I didn't find that in the documentation nor in the tests.
I'd like something like that:

#[macro_use]
extern crate cpp;

cpp!{{
    #include <glm/glm.hpp> 
}}

fn main() {
    let x = cpp![glm::vec3(1,0,0)];
}

@mystor
Copy link
Owner

mystor commented Aug 9, 2017

No, this is not currently possible.

It might be possible to do something like this (allowing opaque C++ types to exist on the Rust stack - you'd still need cpp! blocks to call methods on the types) once we get something like impl trait or if I decide that implicit boxing and virtual call overhead is OK.

@vadimcn
Copy link

vadimcn commented Aug 15, 2017

@mystor, btw, why would you need impl Trait for this?

@mystor
Copy link
Owner

mystor commented Aug 15, 2017

I'm not sure if I would. I had one idea for how to implement it which would require it but I haven't had time to think through the options.

@vadimcn
Copy link

vadimcn commented Aug 15, 2017

I thought you were talking about creating opaque structs of the same size and alignment as their C++ counterparts.

@ogoffart
Copy link
Collaborator

This is now possible with cpp_class! from #28

#[macro_use]
extern crate cpp;

cpp!{{
    #include <glm/glm.hpp> 
}}

cpp_class!(unsafe struct vec3 as "glm::vec3");

fn main() {
    let x = unsafe { cpp!( [] -> vec3 as "glm::vec3" { return glm::vec3(1,0,0)]; }) };
}

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

4 participants