-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
197 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_type>; target_len] = arrr!([<target_type>; target_len], <array>); | ||
``` | ||
|
||
## 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]); | ||
``` |