Skip to content

Commit e632853

Browse files
committed
Initial project
1 parent ada038c commit e632853

15 files changed

+459
-0
lines changed

.editorconfig

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
root = true
2+
3+
[*]
4+
indent_style = tab
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_size = 4
8+
9+
[*.md]
10+
indent_style = space
11+
12+
[*.yml]
13+
indent_style = space
14+

.github/dependabot.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: cargo
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
time: "08:30"
8+
open-pull-requests-limit: 10

.github/workflows/pull-request.yml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Pull Request
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
test:
7+
strategy:
8+
matrix:
9+
version: ['stable', 'nightly']
10+
runs-on: [ubuntu-latest]
11+
timeout-minutes: 5
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: Install latest Rust
15+
uses: actions-rs/toolchain@v1
16+
with:
17+
toolchain: stable
18+
profile: minimal
19+
override: true
20+
- name: Test
21+
run: cargo test
22+
- name: Build
23+
run: cargo build --release
24+
25+
lint:
26+
runs-on: [ubuntu-latest]
27+
timeout-minutes: 5
28+
steps:
29+
- uses: actions/checkout@v2
30+
- name: Install latest Rust
31+
uses: actions-rs/toolchain@v1
32+
with:
33+
toolchain: stable
34+
profile: minimal
35+
override: true
36+
- name: Install latest nightly Rust
37+
uses: actions-rs/toolchain@v1
38+
with:
39+
toolchain: nightly
40+
profile: minimal
41+
- name: Lint
42+
run: "./scripts/lint.bash"
43+
- name: Docs
44+
run: "./scripts/docs.bash"
45+
- name: Format
46+
run: "./scripts/format.bash"

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
coverage
2+
target

.rustfmt.toml

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
binop_separator = "Front"
2+
blank_lines_lower_bound = 0
3+
blank_lines_upper_bound = 1
4+
brace_style = "SameLineWhere"
5+
color = "Auto"
6+
combine_control_expr = false
7+
comment_width = 120
8+
condense_wildcard_suffixes = true
9+
control_brace_style = "ClosingNextLine"
10+
disable_all_formatting = false
11+
empty_item_single_line = true
12+
enum_discrim_align_threshold = 0
13+
error_on_line_overflow = true
14+
error_on_unformatted = true
15+
fn_args_layout = "Tall"
16+
fn_single_line = false
17+
force_explicit_abi = true
18+
force_multiline_blocks = true
19+
format_code_in_doc_comments = true
20+
format_macro_bodies = true
21+
format_macro_matchers = false
22+
format_strings = true
23+
hard_tabs = true
24+
hide_parse_errors = false
25+
imports_indent = "Block"
26+
imports_layout = "HorizontalVertical"
27+
imports_granularity = "Crate"
28+
indent_style = "block"
29+
inline_attribute_width = 0
30+
match_arm_blocks = true
31+
match_arm_leading_pipes = "Never"
32+
match_block_trailing_comma = true
33+
max_width = 120
34+
merge_derives = true
35+
newline_style = "Unix"
36+
normalize_comments = false
37+
normalize_doc_attributes = true
38+
overflow_delimited_expr = true
39+
remove_nested_parens = true
40+
reorder_impl_items = true
41+
reorder_imports = true
42+
group_imports = "StdExternalCrate"
43+
reorder_modules = true
44+
report_fixme = "Never"
45+
report_todo = "Never"
46+
skip_children = false
47+
space_after_colon = true
48+
space_before_colon = false
49+
spaces_around_ranges = false
50+
struct_field_align_threshold = 0
51+
struct_lit_single_line = true
52+
tab_spaces = 4
53+
trailing_comma = "Vertical"
54+
trailing_semicolon = true
55+
type_punctuation_density = "Wide"
56+
unstable_features = true
57+
use_field_init_shorthand = true
58+
use_small_heuristics = "Default"
59+
use_try_shorthand = true
60+
where_single_line = true
61+
wrap_comments = true

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Change Log
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
5+
6+
## 0.1.0 - 2021-07-01
7+
8+
### Added
9+
- Initial project release

CODE_OF_CONDUCT.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6+
7+
## Our Standards
8+
9+
Examples of behavior that contributes to creating a positive environment include:
10+
11+
* Using welcoming and inclusive language
12+
* Being respectful of differing viewpoints and experiences
13+
* Gracefully accepting constructive criticism
14+
* Focusing on what is best for the community
15+
* Showing empathy towards other community members
16+
17+
Examples of unacceptable behavior by participants include:
18+
19+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
20+
* Trolling, insulting/derogatory comments, and personal or political attacks
21+
* Public or private harassment
22+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
23+
* Other conduct which could reasonably be considered inappropriate in a professional setting
24+
25+
## Our Responsibilities
26+
27+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28+
29+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30+
31+
## Scope
32+
33+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34+
35+
## Enforcement
36+
37+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [email protected]. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38+
39+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40+
41+
## Attribution
42+
43+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44+
45+
[homepage]: http://contributor-covenant.org
46+
[version]: http://contributor-covenant.org/version/1/4/

Cargo.toml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[package]
2+
name = "captur"
3+
version = "0.1.0"
4+
authors = ["Tim Oram <[email protected]>"]
5+
description = "Macro to capture whole structs from disjoint fields in a closure."
6+
repository = "https://github.com/MitMaro/captur"
7+
documentation = "https://docs.rs/captur/"
8+
keywords = [ "macro", "capture", "struct" ]
9+
categories = ["rust-patterns"]
10+
readme = "README.md"
11+
license = "ISC"
12+
include = [
13+
"**/*.rs",
14+
"/Cargo.toml",
15+
"/CHANGELOG.md",
16+
"/LICENSE",
17+
"/README.md"
18+
]
19+
edition = "2018"
20+
21+
[lib]
22+
name = "captur"

LICENSE

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Copyright (c) 2021, Tim Oram and all contributors
2+
3+
Permission to use, copy, modify, and/or distribute this software
4+
for any purpose with or without fee is hereby granted, provided
5+
that the above copyright notice and this permission notice appear
6+
in all copies.
7+
8+
The software is provided "as is" and the author disclaims all
9+
warranties with regard to this software including all implied
10+
warranties of merchantability and fitness. In no event shall the
11+
author be liable for any special, direct, indirect, or
12+
consequential damages or any damages whatsoever resulting from
13+
loss of use, data or profits, whether in an action of contract,
14+
negligence or other tortious action, arising out of or in connection
15+
with the use or performance of this software.

README.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[![Crates.io](https://img.shields.io/crates/v/captur.svg)](https://crates.io/crates/captur)
2+
[![docs](https://docs.rs/captur/badge.svg)](https://docs.rs/captur/)
3+
[![GitHub license](https://img.shields.io/github/license/MitMaro/http-request-header)](https://raw.githubusercontent.com/MitMaro/captur/master/LICENSE)
4+
5+
# Captur
6+
7+
Starting in Rust 2021, Rust will no longer capture whole structs and instead will only capture a disjoint set of the fields used in a closure. In some cases, it is necessary to capture the structs to retain a particular drop order. This macro will capture the struct within the closure, ensuring the correct drop order.
8+
9+
## The Fix
10+
11+
The typical fix to this problem is to create an unused reference to the struct.
12+
13+
```rust
14+
let some_struct = SomeStruct::new();
15+
let result = || {
16+
// capture some_struct within the closure
17+
let _ = &some_struct;
18+
println!("{}", some_struct.y);
19+
}
20+
```
21+
22+
While this is trivial to implement in closures where capturing is required, without a comment it, the meaning of the unused line is difficult to determine. This macro provides a self documenting and potentially more concise way to capture the structs.
23+
24+
## Installation and Usage
25+
26+
```toml
27+
[dependencies]
28+
captur = "0.1"
29+
```
30+
31+
```rust
32+
use captur::capture;
33+
34+
fn send_event_and_action(action: &Action, event: Event) {
35+
send(|sender| {
36+
capture!(action, event);
37+
sender.send(action.name.as_str(), event.code);
38+
});
39+
}
40+
```
41+
42+
## License
43+
44+
Captur is released under the ISC license. See [LICENSE](LICENSE).

scripts/docs.bash

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
set -u
5+
set -o pipefail
6+
7+
rustup update stable
8+
cargo +stable doc --all-features
9+
10+
# try to run the nightly version, if it exists, but do not fail
11+
(
12+
rustup update nightly && \
13+
cargo +nightly doc --all-features
14+
) || true

scripts/format.bash

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
set -u
5+
set -o pipefail
6+
7+
RUST_VERSION="nightly"
8+
9+
rustup update "$RUST_VERSION"
10+
rustup component add rustfmt --toolchain "$RUST_VERSION"
11+
cargo +"$RUST_VERSION" fmt --all -- --check
12+

scripts/lint.bash

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
set -u
5+
set -o pipefail
6+
7+
rustup update stable
8+
rustup component add clippy --toolchain stable
9+
cargo +stable clippy --all-targets --all-features
10+
11+
# try to run the nightly version, if it exists, but do not fail
12+
(
13+
rustup update nightly && \
14+
rustup component add clippy --toolchain nightly && \
15+
cargo +nightly clippy --all-targets --all-features
16+
) || true

scripts/test.bash

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
set -u
5+
set -o pipefail
6+
7+
rustup update stable
8+
cargo test

0 commit comments

Comments
 (0)