Crates.io | cpp-like-new |
lib.rs | cpp-like-new |
version | 0.1.0 |
source | src |
created_at | 2023-04-26 08:20:54.509795 |
updated_at | 2023-04-26 08:20:54.509795 |
description | A library that allows you to create/destroy objects in Rust in a similar way to using new/delete expressions in C++ |
homepage | |
repository | https://github.com/xmh0511/cpp-like-new.git |
max_upload_size | |
id | 849167 |
size | 6,560 |
new
, as well as, destroy the object through delete
new
, as well as, destroy the array through delete []
unsafe
(i.e. use them in unsafe context/block)Create a single object like the way in C++
let ptr = new!{ i32 }; // with default initialization
let ptr_init = new!{ i32 {10} }; // with 10 as its initializer
// destroy the created objects
delete!{ ptr };
delete!{ ptr_init };
Create an array object
let size = 2;
let arr = new!{ i32[size] };
let arr_init = new!{ i32[size]{0,1}};
let mul_dim_arr = new!{ i32[size][3][4] };
let two_dim_arr = new!{ i32[size][3] {[0,0,0], [1,2,3]} };
// destroy the created objects
delete!{ [] arr};
delete!{ [] arr_init};
delete!{ [] mul_dim_arr};
delete!{ [] two_dim_arr};