-
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.
refactor(docs): make README.md re-use the usage example
- Loading branch information
1 parent
2e2a25a
commit b7bdef2
Showing
3 changed files
with
79 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -17,6 +17,9 @@ jobs: | |
version: 3.x | ||
repo-token: ${{ secrets.GITHUB_TOKEN }} | ||
- uses: pre-commit/[email protected] | ||
- uses: pkgxdev/setup@v3 | ||
with: | ||
+: gomplate.ca | ||
- name: Set up Rust toolchain | ||
run: rustup update stable && rustup default stable | ||
- name: Lint | ||
|
@@ -26,4 +29,6 @@ jobs: | |
- name: Run tests | ||
run: task test | ||
- name: Build docs | ||
run: cargo doc --verbose | ||
run: | | ||
task render | ||
cargo doc --verbose |
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
 | ||
[](https://crates.io/crates/compose-idents) | ||
[](https://docs.rs/compose-idents) | ||
|
||
# compose-idents | ||
|
||
A procedural macro that allows to construct identifiers from one or more arbitrary parts. | ||
|
||
## Motivation | ||
|
||
Rust's declarative macros do not allow generating new identifiers, because they are designed to operate on | ||
the syntactic level (as opposed to the lexical level) using simple pattern matching. | ||
|
||
For example the following code won't work: | ||
```rust,compile_fail | ||
{{ file.Read "examples/usage.rs" }} | ||
``` | ||
|
||
Here is a more practical example for how to auto-generate names for macro-generated tests for different data types: | ||
```rust | ||
use std::ops::Add; | ||
use compose_idents::compose_idents; | ||
|
||
fn add<T: Add<Output = T>>(x: T, y: T) -> T { | ||
x + y | ||
} | ||
|
||
macro_rules! generate_add_tests { | ||
($($type:ty),*) => { | ||
$( | ||
compose_idents!(test_fn = [test_add_, $type]; { | ||
fn test_fn() { | ||
let actual = add(2 as $type, 2 as $type); | ||
let expected = (2 + 2) as $type; | ||
assert_eq!(actual, expected); | ||
} | ||
}); | ||
)* | ||
}; | ||
} | ||
|
||
generate_add_tests!(u8, u32, u64); | ||
|
||
test_add_u8(); | ||
test_add_u32(); | ||
test_add_u64(); | ||
``` | ||
|
||
For more usage examples look into `examples/` and `tests/` directories of the repository. | ||
|
||
## Alternatives | ||
|
||
There some other tools and projects dedicated to identifier manipulation: | ||
|
||
- A macro from Nightly Rust that allows to concatenate identifiers. It is limited in functionality and nowhere near | ||
to be stabilized: | ||
<https://doc.rust-lang.org/std/macro.concat_idents.html> | ||
- A very similar macro that doesn't support multiple aliases and is not maintained: | ||
<https://github.com/DzenanJupic/concat-idents> | ||
- A macro that allows to define and refer to unique temporary variables: | ||
<https://crates.io/crates/templest> | ||
|
||
## Development | ||
|
||
The following standards are followed to maintain the project: | ||
- <https://www.conventionalcommits.org/en/v1.0.0/> | ||
- <https://semver.org/> | ||
- <https://keepachangelog.com/en/1.1.0/> | ||
- <https://adr.github.io/madr/> |
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 |
---|---|---|
|
@@ -11,3 +11,6 @@ tasks: | |
lint: | ||
cmds: | ||
- pre-commit run --all | ||
render: | ||
cmds: | ||
- gomplate -f README.md.tpl -o README.md |