From 2d63b920679070cf9493990f00e12037db52da26 Mon Sep 17 00:00:00 2001 From: Kenny Strawn Date: Fri, 29 Mar 2024 19:36:52 -0700 Subject: [PATCH] phil-opp/blog_os#1307: bump version and publish --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 2 +- src/lib.rs | 17 +++++++++++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 45d87e1..dfb4415 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,7 +19,7 @@ dependencies = [ [[package]] name = "lazy-heap" -version = "0.1.1-alpha.5" +version = "0.1.1-alpha.6" dependencies = [ "slab_allocator_rs", "spin", diff --git a/Cargo.toml b/Cargo.toml index 2329787..ec89885 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "lazy-heap" description = "A lazy heap allocator for Rust based on `slab_allocator_rs`." repository = "https://github.com/kennystrawnmusic/lazy-heap" -version = "0.1.1-alpha.5" +version = "0.1.1-alpha.6" edition = "2021" license = "LGPL-3.0-or-later" categories = [ "no-std", "memory-management" ] diff --git a/README.md b/README.md index ceb462e..bdcd30f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # `lazy_heap`: A wrapper around the `slab_allocator_rs` crate that allows for lazy initialization -Although there are plenty of global allocators in the crates.io repository, 3 years of tinkering with my own kernel code have taught me that, sometimes, the more time saved, the better. As such, I came up with this in the code to my own kernel but decided, because of just how useful it really is, to actually open it up to the masses. +Although there are plenty of global allocators in the crates.io repository, 3 years of tinkering with [my own kernel code](https://github.com/kennystrawnmusic/cryptos) have taught me that, sometimes, the more time saved, the better. As such, I came up with this in the code to my own kernel but decided, because of just how useful it really is, to actually open it up to the masses. Using this crate allows you to use a closure to initialize the heap automatically (lazily) on the first access attempt: diff --git a/src/lib.rs b/src/lib.rs index 3de182b..b2db43c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,20 @@ +//! # `lazy_heap`: A wrapper around the `slab_allocator_rs` crate that allows for lazy initialization +//! +//! Although there are plenty of global allocators in the crates.io repository, 3 years of tinkering with [my own kernel code](https://github.com/kennystrawnmusic/cryptos) have taught me that, sometimes, the more time saved, the better. As such, I came up with this in the code to my own kernel but decided, because of just how useful it really is, to actually open it up to the masses. +//! +//! ## Usage +//! Using this crate allows you to use a closure to initialize the heap automatically (lazily) on the first access attempt: +//! +//! ```rust +//! use lazy_heap::LazyHeap; +//! #[global_allocator] +//! pub static ALLOC: LazyHeap = LazyHeap::new(|| { +//! // allocator initialization code goes here +//! }) +//! ``` +//! +//! This is a much more seamless, much less error-prone, set-it-and-forget-it way to initialize heap allocation than any other approach, because, with it, you can be guaranteed that any first attempt to use `alloc` will automatically initialize the heap for you. + use core::alloc::{GlobalAlloc, Layout}; use spin::Lazy;