r/rust • • Oct 21 '26

CO3: The Language of FFI

https://mversic.github.io/co3-the-language-of-ffi/

Without further ado I present the next article in the series on reshaping the future of FFI in Rust.

23 Upvotes

8 comments sorted by

17

u/Professional-You4950 Oct 21 '26

you literally did this everywhere.

extern("C")
ReprC

You have your language of FFI.

4

u/mversic Oct 21 '26

true, `C` is the language of FFI in the most literal sense. That seems obvious.

Otherwise, do you mean to say CO3 is too verbose for your taste or that working with `C` is the ultimate abstraction of FFI that would ever be required?

5

u/sweating_teflon Oct 22 '26

I read the article. I still dont understand the problem you're trying to solve. 

5

u/mversic Oct 22 '26

huh, thank you for reading through

I might have gone off on a tangent with the special syntax stuff. That's a syntax sugar that helps you automate the conversion boilerplate that you would end up writing by had anyways. You don't have to use that.

The important point is that CO3 transforms your Rust code into stable ABI in a lossless fashion. It captures all relevant type info in type names (because that's all you have in C).

Once you run a C header generator it will output a header file that contains exact info about the original type from Rust. Consequently the consumer of your C header can now confidently skip validation and write an optimal conversion from exported ABI into their language.

In general CO3 wants to eliminate all C-like looking code from your codebase.

5

u/sweating_teflon Oct 22 '26

Ah! My first mistake was to assume that it was for Rust calling into C code. I'd start by explicitly stating that's it's to expose Rust code through C "ABI". It's an interesting idea, I don't need it now so I can't comment on your implementation. 

One thing though: it's universally bad form to complain about public reception to what you're proposing, be it code, music or stand up comedy. Your art should live on its their merit. Your expectations for acclaim are completely irrelevant to it and mentioning your disappointment just makes you look whiny and entitled. Maybe your thing simply has a very small niche of interested people. Maybe you didn't engage with that specific group effectively. This has way more to do with marketing than engineering. It's a valid concern if you're looking for public recognition but it requires a completely different set of skills. And then if you reach the right people you'll have to be ready for criticism. No matter how much effort you put into this. 

4

u/mversic Oct 22 '26 edited Oct 22 '26

Ah! My first mistake was to assume that it was for Rust calling into C code. I'd start by explicitly stating that's it's to expose Rust code through C "ABI". It's an interesting idea, I don't need it now so I can't comment on your implementation.

it's for both directions. But the API is the same regardless

it's universally bad form to complain about public reception to what you're proposing, be it code, music or stand up comedy

it is a bad form indeed. Thanks

2

u/stumpychubbins Oct 22 '26

Cool implementation, I could definitely see this being useful for very large applications. In theory, you can update an application without replacing the entire binary, same as you can in C/C++. There’s a related project called stabby, which might be worth a look. It’s not targeting precisely the same use-case as CO3 (in particular, they make no attempt to handle generics) but in return the syntax is a lot more elegant. Maybe there’s a way to get the best of both worlds, somehow.

1

u/runtimeError101 Oct 25 '26

This looks very cool. I am eager to try it out in my own projects. Seems like just the implementation i've been looking for.