CRust

From Computernewb Wiki
Jump to navigation Jump to search

CRust is a satirical programming paradigm that blends elements of C and Rust, designed to address what its creator perceives as Rust's verbosity and complexity. Developed by Tsoding, CRust is described as "Rust that is actually Fun" in its original GitHub repository with a goal to "make programming in Rust fun".

The paradigm consists of a straightforward set of rules and is compatible exclusively with Rust edition 2021. CRust is intended primarily as a humorous project and is not recommended for use in production environments.

Rules

CRust is a paradigm consisting of 7 rules:

  1. Every function is unsafe.
  2. No references, only pointers.
  3. No cargo, build with rustc directly.
  4. No std, but libc is allowed.
  5. Only [Rust] Edition 2021.
  6. All user structs and enums[:] #[derive(Clone, Copy)].
  7. Everything is pub by default.

These rules are defined in its GitHub repository at https://github.com/tsoding/crust and currently this paradigm is used in Tsoding's B language compiler.

Licensing

CRust is licensed under the MIT license by Tsoding.

Examples

Hello World

// Compile with: rustc hello.rs -C panic=abort --edition=2021

#![no_std]
#![no_main]

use core::panic::PanicInfo;

#[panic_handler]
pub unsafe fn panic(_info: &PanicInfo) -> ! {
    loop {}
}

#[link(name = "c")]
unsafe extern "C" {
    fn puts(s: *const u8) -> i32;
}

#[no_mangle]
pub unsafe extern "C" fn main(_argc: i32, _argv: *mut *mut u8) -> i32 {
    let msg: *const u8 = b"Hello, World!\0".as_ptr();
    puts(msg);
    return 0;
}