Skip to content

use zig code in rust - a medium effort shitpost

Notifications You must be signed in to change notification settings

natanalt/zig2rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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?

Ferris the Crab and Zero the Ziguana cuddling on a raft

How?

It's a small macro you can use:

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 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

About

use zig code in rust - a medium effort shitpost

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages