This only adds this as nix module. So running `nix fmt` will now format
all files under the repo root.
If you want to run this as non-nix user feel free to take a look at the
generated `treefmt.toml`.
The old implementation tried to provide rust types in c—like the
result or option types. This implementation now removes this source of
complexity by ensuring, that these types are unwrapped on the rust->c
boundary.
This first commit changes the header files to conform to the new api.
This changes two important things:
- Firstly it renames the `nasp` keyword to `mod`:
This change removes the not required deviation from rust.
- Secondly it removes the semicolon after an enumeration or structure
declaration, which is pointless in these positions.
These are implemented right now by simply casting the generic arguments
to void pointers and providing a `type_id` field in every struct
denoting the original type.
This implementation, whilst being extremely unwieldy to work with on
the c side, also fails in a lot of fundamental ways:
1. The `type_id` enum *can* never really support user defined
types because we would already need it to provide the c to rust
value conversion.
2. Even without custom user types the type conversion is extremely
hard to correctly implement in a somewhat performant way: A vector
passed from c code to rust would need to completely reallocated
*one element at a time*. And this only works if the c side has
correctly cast the void pointer to the vectors data before accessing
it, as any other way would have lead to possible unaligned data
(which the rust side had to account for).
3. The c api is just simply bad in this state:
You have to always look at the Trixy file to even be able to deal
with the data the api returns (that is: There is no mention of
a results generics in the c header). Additionally the question
arises if these types should even be leaked into the c code because
than c just becomes a worse version of rust, which undermines the
whole reason of providing a c api in the first place.
One way to fix all these issues would be to change the way generics are
handled by using unions instead of the void pointer and trying to avoid
leaking these rust types in c as far as possible.
This approach would require a lot less binding code (both on the c and
rust side), but also would make the rust based c-header-gen-code harder,
as it would then be required to turn a `Vec<String>` to a `char **` (and
obviously a whole wrapper struct with size and string length), whilst
turning a `Vec<char>` to a `char*` differentiating it from a `string_t`.