From 34467f7c332686e3d2588bb7ef2a347cc9498087 Mon Sep 17 00:00:00 2001 From: rexim Date: Fri, 7 Nov 2025 22:29:08 +0700 Subject: [PATCH 1/2] Add more details to the rules --- README.md | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 1d5d3b5..51faf4d 100644 --- a/README.md +++ b/README.md @@ -4,14 +4,46 @@

-1. Every function is unsafe. -1. No references, only pointers. -1. No cargo, build with rustc directly. -1. No std, but libc is allowed. -1. Only Edition 2021. -1. All user structs and enums #[derive(Clone, Copy)]. -1. Everything is pub by default. - *The list of rules may change. The goal is to make programming in Rust fun.* Currently used in the [B Compiler Project](https://github.com/tsoding/b). + +## 1. No std. + +Use [`#![no_std]`][no_std] attribute to enforce this rule. [core][core] is allowed because there is currently [no stable way to disable it](https://github.com/rust-lang/rust/issues/29639). Using libc is allowed since rustc links with it anyway. But since no cargo is allowed you have to declare the necessary libc functions yourself in your crate. + +You may also consider enabling [`#![no_main]`][no_main] and provide your custom C-style entry point to be able to get an access to command line arguments. + +## 2. Every function is unsafe. + +Every single user-made function must be marked as unsafe. + +## 3. Raw pointers instead of references. + +Raw pointers instead of references must be used for: + +1. Parameters and results of all the user-made functions; +2. Members of user-made structs and enums; +3. User-made global variables; + +In the bodies of the functions references are allowed to be used for local variables and intermediate variables. + +## 4. No cargo. + +Build with rustc directly pure C-style. Linking with external C libraries is encouraged. + +## 5. Only Edition 2021. + +Newer additions are too hostile towards Crust. + +## 6. Copy by default. + +All user-made structs and enums must be `#[derive(Clone, Copy)]` + +## 7. Public by default. + +Everything is `pub` by default. + +[core]: https://doc.rust-lang.org/stable/core/index.html +[no_std]: https://doc.rust-lang.org/reference/names/preludes.html#the-no_std-attribute +[no_main]: https://doc.rust-lang.org/reference/crates-and-source-files.html?highlight=no_main#the-no_main-attribute From 2e287c762cd596f032f8c876eef0c6c243198626 Mon Sep 17 00:00:00 2001 From: rexim Date: Fri, 7 Nov 2025 22:52:52 +0700 Subject: [PATCH 2/2] Typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 51faf4d..f02f320 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Raw pointers instead of references must be used for: 2. Members of user-made structs and enums; 3. User-made global variables; -In the bodies of the functions references are allowed to be used for local variables and intermediate variables. +In the bodies of the functions references are allowed to be used for local variables and intermediate value. ## 4. No cargo.