#extension #macro #structures #standard #simplifying #structure

std-macro-extensions

A collection of macro extensions for Rust's standard library data structures, simplifying the creation and manipulation of common collections such as HashMap, Vec, and more

27 releases (16 breaking)

new 0.18.0 Jan 7, 2025
0.17.6 Dec 29, 2024
0.17.0 Nov 30, 2024

#350 in Data structures

Download history 1309/week @ 2024-10-22 45/week @ 2024-10-29 5/week @ 2024-11-19 158/week @ 2024-11-26 155/week @ 2024-12-03 88/week @ 2024-12-10 6/week @ 2024-12-17 423/week @ 2024-12-24 206/week @ 2024-12-31

831 downloads per month
Used in 4 crates

MIT license

26KB
394 lines

std-macro-extensions

Official Documentation

A collection of macro extensions for Rust's standard library data structures, simplifying the creation and manipulation of common collections such as HashMap, Vec, and more.

Features

  • Simplified Initialization: Use macros to easily create instances of common data structures.
  • Supports Various Data Structures: Includes macros for Vec, HashMap, Arc, and more.
  • Easy to Use: Intuitive syntax for quick data structure creation.

Installation

To install std-macro-extensions run cmd:

cargo add std-macro-extensions

Usage

Here are some examples of how to use the macros provided by this crate:

Example: Using arc!

use std_macro_extensions::*;

fn main() {
    let value = arc!(5);
}

Example: Using b_tree_map!

use std_macro_extensions::*;

fn main() {
    let empty_map: BTreeMap<i32, i32> = b_tree_map!();
    let b_tree_map_a: BTreeMap<&str, &str> = b_tree_map!(
        "a" => "a",
        "b" => "b"
    );
}

Example: Using b_tree_set!

use std_macro_extensions::*;

fn main() {
    let empty_set: BTreeSet<i32> = b_tree_set!();
    let number_set: BTreeSet<i32> = b_tree_set!(1, 2, 3);
}

Example: Using binary_heap!

use std_macro_extensions::*;

fn main() {
    let empty_set: BTreeSet<i32> = b_tree_set!();
    let number_set: BTreeSet<i32> = b_tree_set!(1, 2, 3);
}

Example: Using boxed!

use std_macro_extensions::*;

fn main() {
    let boxed_value = boxed!(10);
}

Example: Using cell!

use std_macro_extensions::*;

fn main() {
    let cell_value: Cell<i32> = cell!(5);
}

Example: Using hash_map!

use std_macro_extensions::*;

fn main() {
    let my_map: HashMap<&str, i32> = hash_map!();
    let my_map: HashMap<&str, i32> = hash_map!("a" => 1, "b" => 2);
}

Example: Using hash_set!

use std_macro_extensions::*;

fn main() {
    let my_set: HashSet<i32> = hash_set!();
    let my_set: HashSet<i32> = hash_set!(1, 2, 3);
}

Example: Using linked_list!

use std_macro_extensions::*;

fn main() {
    let my_list: LinkedList<i32> = linked_list!();
    let my_list: LinkedList<i32> = linked_list!(1, 2, 3);
}

Example: Using mutex!

use std_macro_extensions::*;

fn main() {
    let my_mutex: Mutex<i32> = mutex!(5);
    let lock: MutexGuard<'_, i32> = my_mutex.lock().unwrap();
}

Example: Using rc!

use std_macro_extensions::*;

fn main() {
    let my_rc = rc!(5);
}

Example: Using refcell!

use std_macro_extensions::*;

fn main() {
    use std_macro_extensions::*;
    let my_refcell = refcell!(5);
}

Example: Using rw_lock!

use std_macro_extensions::*;

fn main() {
    let my_rwlock = rw_lock!(5);
}

Example: Using string!

use std_macro_extensions::*;

fn main() {
    let empty_string = string!();
    let hello_string = string!("Hello");
}

Example: Using vector!

use std_macro_extensions::*;

fn main() {
    let empty_vector: Vec<i32> = vector!();
    let numbers = vector!(1, 2, 3);
}

Example: Using vector_deque!

use std_macro_extensions::*;

fn main() {
    let empty_deque: VecDeque<i32> = vector_deque!();
    let numbers = vector_deque!(1, 2, 3);
}

Example: Using join_paths!

let combined_path: String = join_paths!("/home/", "/user/", "/documents", "file.txt");
let another_path: String = join_paths!("C:/", "/Program Files", "App");

Available Macros

  • arc!: Creates an Arc<T>.
  • vector!: Creates a Vec<T>.
  • map!: Creates a HashMap<K, V>.
  • set!: Creates a HashSet<T>.
  • b_tree_map!: Creates a BTreeMap<K, V>.
  • b_tree_set!: Creates a BTreeSet<T>.
  • list!: Creates a LinkedList<T>.
  • heap!: Creates a BinaryHeap<T>.
  • string!: Creates a String.
  • boxed!: Creates a Box<T>.
  • rc!: Creates an Rc<T>.
  • arc!: Creates an Arc<T>.
  • mutex!: Creates a Mutex<T>.
  • rw_lock!: Creates a RwLock<T>.
  • cell!: Creates a Cell<T>.
  • ref_cell!: Creates a RefCell<T>.
  • vector_deque!: Creates a VecDeque<T>.
  • join_paths!: Combines multiple paths into a single valid path, handling overlapping slashes.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

Contact

For any inquiries, please reach out to the author at ltpp-universe [email protected].

No runtime deps