From 841ec6f68ae4d99b3a201fed30a920afb34802ef Mon Sep 17 00:00:00 2001 From: tuguzT Date: Fri, 19 Aug 2022 17:42:13 +0300 Subject: [PATCH] Prepare for release 0.1.0 --- Cargo.toml | 5 ++++- README.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 README.md diff --git a/Cargo.toml b/Cargo.toml index 62ae43c..dc510fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,11 @@ [package] name = "ref_kind" -version = "0.0.0" +version = "0.1.0" description = "Different reference kinds" authors = ["tuguzT "] repository = "https://github.com/toucan-rust/ref_kind" license = "MIT OR Apache-2.0" +readme = "README.md" +keywords = ["ref", "safe", "mutability"] +categories = ["data-structures", "rust-patterns"] edition = "2021" diff --git a/README.md b/README.md new file mode 100644 index 0000000..07d55ca --- /dev/null +++ b/README.md @@ -0,0 +1,45 @@ +# ref_kind + +[![Crate](https://img.shields.io/crates/v/ref_kind.svg)](https://crates.io/crates/ref_kind) +[![Docs](https://docs.rs/ref_kind/badge.svg)](https://docs.rs/ref_kind) +![License](https://img.shields.io/badge/license-MIT%20OR%20Apache%202.0-blue.svg) + +Different reference kinds in Rust. + +Provides 2 kinds of reference: immutable and mutable. All of them represented in one enum `RefKind`, +which allows you to store immutable and mutable references together. + +In addition, this crate contains `RefKindMap` which is a `HashMap` of reference kinds. +This structure can easily be created from `HashMap` iterator (immutable or mutable one): + +```rust +use std::collections::HashMap; +use ref_kind::RefKindMap; + +let mut map = HashMap::new(); +map.insert("Hello World", 0); +map.insert("The Answer to the Ultimate Question of Life, the Universe, and Everything", 42); + +let mut refs = map.iter_mut().map(|(&k, v)| (k, v)).collect::>(); +``` + +Then it can be used to retrieve multiple mutable references from the `HashMap`: + +```rust +let hello = refs.move_mut("Hello World").unwrap(); +let answer = refs.move_mut("The Answer to the Ultimate Question of Life, the Universe, and Everything").unwrap(); + +assert_eq!(*hello, 0); +assert_eq!(*answer, 42); +``` + +No `unsafe` code is needed! + +## License + +Licensed under either of + +- Apache License, Version 2.0, () +- MIT license () + +at your option. diff --git a/src/lib.rs b/src/lib.rs index 518c51b..d975301 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,46 @@ #![forbid(unsafe_code)] //! Different reference kinds in Rust. +//! +//! Provides 2 kinds of reference: immutable and mutable. All of them represented in one enum [`RefKind`], +//! which allows you to store immutable and mutable references together. +//! +//! In addition, this crate contains [`RefKindMap`] which is a [`HashMap`] of reference kinds. +//! This structure can easily be created from [`HashMap`] iterator (immutable or mutable one): +//! +//! ``` +//! use std::collections::HashMap; +//! use ref_kind::RefKindMap; +//! +//! let mut map = HashMap::new(); +//! map.insert("Hello World", 0); +//! map.insert("The Answer to the Ultimate Question of Life, the Universe, and Everything", 42); +//! +//! let mut refs = map.iter_mut().map(|(&k, v)| (k, v)).collect::>(); +//! ``` +//! +//! Then it can be used to retrieve multiple mutable references from the [`HashMap`]: +//! +//! ``` +//! # use std::collections::HashMap; +//! # use ref_kind::RefKindMap; +//! # +//! # let mut map = HashMap::new(); +//! # map.insert("Hello World", 0); +//! # map.insert("The Answer to the Ultimate Question of Life, the Universe, and Everything", 42); +//! # +//! # let mut refs = map.iter_mut().map(|(&k, v)| (k, v)).collect::>(); +//! # +//! let hello = refs.move_mut("Hello World").unwrap(); +//! let answer = refs.move_mut("The Answer to the Ultimate Question of Life, the Universe, and Everything").unwrap(); +//! +//! assert_eq!(*hello, 0); +//! assert_eq!(*answer, 42); +//! ``` +//! +//! No `unsafe` code is needed! +//! +//! [`HashMap`]: std::collections::HashMap pub use kind::RefKind; pub use map::RefKindMap;