├── .gitignore ├── README.md ├── rustify.cpp └── rustify.hpp /.gitignore: -------------------------------------------------------------------------------- 1 | a.out 2 | rustify.hpp.gch -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rustifying c++ 2 | 3 | ## Code example 4 | 5 | ```c++ 6 | #include "rustify.hpp" 7 | #include 8 | #include 9 | #include 10 | 11 | struct Hello { 12 | public: 13 | static fn hello() -> String; 14 | }; 15 | 16 | fn Hello::hello() -> String { 17 | return "World!"; 18 | } 19 | 20 | enum Test { 21 | Thing, 22 | Also 23 | }; 24 | 25 | fn hello(String h) -> i32 { 26 | println("Hello World"); 27 | return 5; 28 | } 29 | 30 | fn other(str x) -> void { 31 | println(x); 32 | } 33 | 34 | fn main() -> i32 { 35 | println("Hello World"); 36 | other("Hello Other"); 37 | 38 | Vec x = {1, 2, 3, 4}; 39 | 40 | for (auto& i : x) 41 | println(i); 42 | 43 | Test t = Thing; 44 | 45 | println(Hello::hello()); 46 | 47 | match(t) { 48 | case Thing: 49 | println("It is a thing"); 50 | break; 51 | } 52 | 53 | return 0; 54 | } 55 | ``` 56 | -------------------------------------------------------------------------------- /rustify.cpp: -------------------------------------------------------------------------------- 1 | #include "rustify.hpp" 2 | #include 3 | #include 4 | #include 5 | 6 | struct Hello { 7 | public: 8 | static fn hello() -> String; 9 | }; 10 | 11 | fn Hello::hello() -> String { 12 | return "World!"; 13 | } 14 | 15 | enum Test { 16 | Thing, 17 | Also 18 | }; 19 | 20 | fn hello(String h) -> i32 { 21 | println("Hello World"); 22 | return 5; 23 | } 24 | 25 | fn other(str x) -> void { 26 | println(x); 27 | } 28 | 29 | fn main() -> i32 { 30 | println("Hello World"); 31 | other("Hello Other"); 32 | 33 | Vec x = {1, 2, 3, 4}; 34 | 35 | for (auto& i : x) 36 | println(i); 37 | 38 | Test t = Thing; 39 | 40 | println(Hello::hello()); 41 | 42 | match(t) { 43 | case Thing: 44 | println("It is a thing"); 45 | break; 46 | } 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /rustify.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #define use #include 8 | 9 | #define i16 __int16 10 | #define i32 int 11 | #define i64 __int64 12 | #define i128 __int128 13 | 14 | #define fn auto 15 | #define str const char* 16 | #define String std::string 17 | #define println(x) std::cout << x << std::endl; 18 | #define struct class 19 | #define trait concept 20 | 21 | #define Vec std::vector 22 | #define match switch 23 | --------------------------------------------------------------------------------