Hacker News new | past | comments | ask | show | jobs | submit login

Not sure what you mean by "object oriented C". It doesn't support C++ presently (something I'd love to see improved); there are some projects that do Objective-C interop; if you just mean C that uses structs in an OO-like way, it shouldn't be that different from any other C.



I assume parent meant something like GObject, where you get opaque reference counted structs. (Generally something like gobject-introspection is used to generically bind it to other languages, not auto-generated wrappers.)


Yes, when using structs in an OO like way. Does it generate c-style rust wrapper ? or can it generate class-based rust wrapper ,perhaps with some guidance ?


AFAIK, rust-bindgen doesn't currently have support for translating C functions and structs into anything other than the same things in Rust. It's somewhat idiomatic for manually-written bindings, layered on top of the generated ones, to take care of things like providing a memory-safe interface (which can't really be done automatically), converting between native Rust types and C representations if necessary (perhaps including things like Result vs. error codes or nulls), and adding object orientation. If you want to go full automatic, though, you can do a lot with Rust macros, so give them a try.

Examples of manual wrappers on top of bindgen - there are many:

http://erickt.github.io/blog/2014/12/13/rust-and-mdbm/

https://github.com/kenz-gelsoft/wxRust/blob/rust-servo/src/b... (I don't like the design of this one, actually)

https://github.com/rust-gnome/gtk/blob/master/src/widgets/ac... (better)




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: