From b3403cd6cc68aa22a1587d865fdb1df8f62f3fe6 Mon Sep 17 00:00:00 2001 From: Avril Date: Sat, 27 Mar 2021 00:59:11 +0000 Subject: [PATCH] update README --- .#Cargo.toml | 1 + Cargo.toml | 3 ++- README.md | 12 ------------ 3 files changed, 3 insertions(+), 13 deletions(-) create mode 120000 .#Cargo.toml diff --git a/.#Cargo.toml b/.#Cargo.toml new file mode 120000 index 0000000..fd4f1cb --- /dev/null +++ b/.#Cargo.toml @@ -0,0 +1 @@ +avril@eientei.1009:1616693269 \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index b34cd6a..5af13b7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,10 @@ [package] name = "stackalloc" -version = "0.1.0" +version = "1.0.0" description = "allocate arbitrary data on the stack at runtime" authors = ["Avril "] edition = "2018" +license = "MIT" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/README.md b/README.md index 48000db..a380e4e 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,6 @@ The crate works on stable or nightly Rust, but a C99-compliant compiler is requi # Examples Allocating a byte buffer on the stack. ```rust -# use std::io::{self, Write, Read}; -# use stackalloc::*; fn copy_with_buffer(mut from: R, mut to: W, bufsize: usize) -> io::Result { alloca_zeroed(bufsize, move |buf| -> io::Result { @@ -32,29 +30,20 @@ fn copy_with_buffer(mut from: R, mut to: W, bufsize: usize) - ## Arbitrary types Allocating a slice of any type on the stack. ```rust -# use stackalloc::stackalloc; -# fn _prevent_attempted_execution() { stackalloc(5, "str", |slice: &mut [&str]| { assert_eq!(&slice[..], &["str"; 5]); }); -# } ``` ## Dropping The wrapper handles dropping of types that require it. ```rust -# use stackalloc::stackalloc_with; -# fn _prevent_attempted_execution() { stackalloc_with(5, || vec![String::from("string"); 10], |slice| { assert_eq!(&slice[0][0][..], "string"); }); // The slice's elements will be dropped here -# } ``` # `MaybeUninit` You can get the aligned stack memory directly with no initialisation. ```rust -# use stackalloc::stackalloc_uninit; -# use std::mem::MaybeUninit; -# fn _prevent_attempted_execution() { stackalloc_uninit(5, |slice| { for s in slice.iter_mut() { @@ -70,7 +59,6 @@ stackalloc_uninit(5, |slice| { std::ptr::drop_in_place(slice as *mut [String]); } }); -# } ``` # How does it work?