Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/natanalt/zig2rs
use zig code in rust - a medium effort shitpost
https://github.com/natanalt/zig2rs
Last synced: about 1 month ago
JSON representation
use zig code in rust - a medium effort shitpost
- Host: GitHub
- URL: https://github.com/natanalt/zig2rs
- Owner: natanalt
- Created: 2022-02-11T20:48:11.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-02-11T20:52:18.000Z (about 3 years ago)
- Last Synced: 2024-09-25T16:09:06.706Z (5 months ago)
- Language: Rust
- Homepage:
- Size: 97.7 KB
- Stars: 18
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-rust-list - natanalt/zig2rs - a medium effort shitpost. (FFI Bindings)
- awesome-rust-list - natanalt/zig2rs - a medium effort shitpost. (FFI Bindings)
README
# ✨ *zig2rs* ✨
Have you ever wanted to use two of the objectively best programming languages out there - Rust and Zig - at the same time? Has linking applications through C ABI tired you? Well then look no further, as my solution will revolutionise the world of software development!## Why?
## How?
It's a small macro you can use:
```rust
unsafe fn print_string(ptr: *const u8, len: usize) {
let slice = std::slice::from_raw_parts(ptr, len);
let string = std::str::from_utf8(slice).unwrap();
println!("{}", string);
}zig2rs! {
fn hello_world(times: usize) void {
const message = "this is a crime";
var i: usize = 0;
while (i < times) : (i += 1) {
print_string(message.ptr, message.len);
}
}
}fn main() {
unsafe {
hello_world(3);
}
}
```
You can't actually use any good features Zig has going for itself, but shhh be quiet. This example is about everything this thing can do, and anything else will anger the compiler.## Who?
hi, [I](https://github.com/natanalt) did this medium effort shitpost## What's next?
Someday I may write a proper compiler using procedural macros instead of `macro_rules!` which would allow for much greater flexibility, lack of which is why this macro is so limited