Our great sponsors
-
diplomat
Experimental Rust tool for generating FFI definitions allowing many other languages to call Rust code
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
-
serde-reflection
Rust libraries and tools to help with interoperability and testing of serialization formats based on Serde. (by zefchain)
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
-
marker
An experimental linting interface for Rust. Let's make custom lints a reality (by rust-marker)
At work we do something similar from GraphQL https://github.com/lookback/bifrost
Thanks! Yeah, it's not on crates.io for a reason :D
rfc https://rust-lang.github.io/rfcs/2963-rustdoc-json.html and tracking issue https://github.com/rust-lang/rust/issues/
Also, Google doesn't have official protobuf implementations for JS/TS, PHP, or Rust. The officially supported languages are listed here. The implementations you're describing may well be trash but that's not really a fair reflection of the quality of protobuf itself.
If you don’t mind writing definitions in a third language and making your own generator scripts, you could use my code generator: https://github.com/hardliner66/ssdcg
Facebook had/has? Thrift as a more "proper" IDL.
We do this at work, except with Haskell types: https://github.com/MercuryTechnologies/moat
Hey, I might be able to give some input how I deal with it in [rust-linting](https://github.com/rust-linting/rust-linting). For some context, the project needs to load several dynamic libraries and provide each of them with an abstract syntax tree. Serializing and deserializing the types for every step would most likely be too expensive. That's why I opted for a Rust <-> Rust FFI. There are two parts of this: 1. The loaded libraries needed to accept data from a driver. For this, I generate functions in the library crates which are marked as `extern "C"` and only use FFI safe types. Passing information to the loaded crates then always calls the generated functions, which intern call access a thread local struct instance in the dynamic crate. It's important that the instance implement a specific trait. For the library creation, it seems like magic. 2. Callbacks. The loaded libraries need to pass information back to the driver. For this, I use a struct with function pointers. These are also marked as `extern "C"` and need to only use FFI safe types. The definition of FFI safe, is a bit difficult. Slices, `str`, `Option<>` and most of the rusts STD types don't have a stable layout to the point, that it can change between compilations with the same compiler. Therefore, it's required that each passed type is `#[repr(C)]`. Options are wrapped in an enum, which has `#[repr(C)]`, slices and strings are dismantled into a data pointer and a length. On the receiving and they're reconstructed again. A small warning. I'm not an expert on FFI interfaces. My implementation would probably have some problems with lifetimes, if I'd use a slightly different memory model. So far, this has worked well (Besides the required boilerplate). The project is currently sadly lacking documentation, as it's still under heavy development. If you want, feel free to lock around the code base. The stable types and most of the interface is inside the `linter_api` crate.
This seems like it could be super useful for integrating with wasm-bindgen and TypeScript. Last I checked, the types generated by wasm-bindgen left a lot to be desired (no disrespect intended, wasm-bindgen is an awesome project). A few years ago, I contributed the skip_typescript attribute to wasm_bindgen that allowed you to override the type generation by hand-writing your own types (using a custom typescript section), but I wonder if this could simply generate higher quality types without the manual intervention.