Skip to content

Commit

Permalink
add readme and gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
acovaci committed May 17, 2024
1 parent dc52642 commit c0bec42
Show file tree
Hide file tree
Showing 2 changed files with 197 additions and 3 deletions.
116 changes: 115 additions & 1 deletion .gitignore
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/
84 changes: 82 additions & 2 deletions README.md
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]);
```

0 comments on commit c0bec42

Please sign in to comment.