From c0bec4258355a208362fd494aee4a7d67d896078 Mon Sep 17 00:00:00 2001 From: Adrian Covaci <6562353+acovaci@users.noreply.github.com> Date: Fri, 17 May 2024 11:07:01 +0100 Subject: [PATCH] add readme and gitignore --- .gitignore | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++- README.md | 84 +++++++++++++++++++++++++++++++++++++- 2 files changed, 197 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index ea8c4bf..b66d773 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,115 @@ -/target +# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,rust,macos,windows,linux +# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,rust,macos,windows,linux + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### macOS Patch ### +# iCloud generated files +*.icloud + +### Rust ### +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,rust,macos,windows,linux + +.vscode/ diff --git a/README.md b/README.md index e8d446d..b13dd39 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,82 @@ -# expand-array-rust-macro -A Rust proc_macro that can expand fixed size array from a smaller length input. +# Expand Array Rust Macro + +This project is a simple macro that allows you to expand an array into a list of +arguments. This is useful when you need to make available global constants in a +dynamic library, for example. + +## Limitations + +The library can only convert string-like types for now. This is what I needed +for my project, but I'm more than happy to accept pull requests that add more +types. + +Available types: + +- `u8`, from: + - `[u8]` + - `[i8]` + - `[byte char]` + - `byte string` + - `&str` + - `c_char` + - `c string` +- `char`, from: + - `[char]` + - `&str` +- `c_char`, from: + - `[u8]` + - `[i8]` + - `[byte char]` + - `byte string` + - `&str` + - `c_char` + - `c string` + +## Usage + +```rust +use expand_array::arrr; + +let var: [; target_len] = arrr!([; target_len], ); +``` + +## Example + +```rust +use expand_array::arrr; + +let arr: [u8; 10] = arrr!([u8; 10], [1, 2, 3, 4, 5]); +assert_eq!(arr, [1, 2, 3, 4, 5, 0, 0, 0, 0, 0]); + +let arr: [u8; 10] = arrr!([u8; 10], b"Hello"); +assert_eq!(arr, [72, 101, 108, 108, 111, 0, 0, 0, 0, 0]); + +let arr: [u8; 10] = arrr!([u8; 10], "Hello"); +assert_eq!(arr, [72, 101, 108, 108, 111, 0, 0, 0, 0, 0]); + +let arr: [char; 10] = arrr!([char; 10], ['H', 'e', 'l', 'l', 'o']); +assert_eq!(arr, ['H', 'e', 'l', 'l', 'o', '\0', '\0', '\0', '\0', '\0']); + +let arr: [char; 10] = arrr!([char; 10], "Hello"); +assert_eq!(arr, ['H', 'e', 'l', 'l', 'o', '\0', '\0', '\0', '\0', '\0']); + +use ::std::ffi::c_char; + +let arr: [c_char; 10] = arrr!([c_char; 10], [72i8, 101i8, 108i8, 108i8, 111i8]); +assert_eq!(arr, [72i8, 101i8, 108i8, 108i8, 111i8, 0i8, 0i8, 0i8, 0i8, 0i8]); + +let arr: [c_char; 10] = arrr!([c_char; 10], c"Hello"); +assert_eq!(arr, [72i8, 101i8, 108i8, 108i8, 111i8, 0i8, 0i8, 0i8, 0i8, 0i8]); + +let arr: [c_char; 10] = arrr!([c_char; 10], [72u8, 101u8, 108u8, 108u8, 111u8]); +assert_eq!(arr, [72i8, 101i8, 108i8, 108i8, 111i8, 0i8, 0i8, 0i8, 0i8, 0i8]); + +let arr: [c_char; 10] = arrr!([c_char; 10], [b'H', b'e', b'l', b'l', b'o']); +assert_eq!(arr, [72i8, 101i8, 108i8, 108i8, 111i8, 0i8, 0i8, 0i8, 0i8, 0i8]); + +let arr: [c_char; 10] = arrr!([c_char; 10], b"Hello"); +assert_eq!(arr, [72i8, 101i8, 108i8, 108i8, 111i8, 0i8, 0i8, 0i8, 0i8, 0i8]); + +let arr: [c_char; 10] = arrr!([c_char; 10], "Hello"); +assert_eq!(arr, [72i8, 101i8, 108i8, 108i8, 111i8, 0i8, 0i8, 0i8, 0i8, 0i8]); +```