Filtered Blocks
Nobody has claimed this yet.
- Dominant language
- Markdown
- Stars
- 6.6k
- Forks
- 1.7k
- Avg merge
- 16h 14m
- Merged PRs (30d)
- 1
Description
In https://www.youtube.com/watch?v=QM1iUe6IofM the speaker describes an interesting idea that may be summarized as a block that explicitly states which variables from the enclosing scope will be used. Read/write is not explicit, only usage.
Today a plain-nested block that accesses the enclosing scope looks like this,
fn main() {
let mut foo = 5;
// Other variables
{
foo += 2;
}
assert_eq!(7, foo);
}
For lengthier blocks such as,
lfn main() {
let mut foo = 5;
let bar = 6;
// Many other variables
{
foo += 2;
// Other lines of code, only by inspection
// can we tell what was used. Maybe bar was
// used, maybe not. We'd have to study the code
// to know
}
assert_eq!(7, foo);
}
there may be several of the preceding variables in the enclosing scope used inside the block.
If we could specify which variables that we'll access inside the nested block we could write something like,
using foo, bar {
// uses foo, bar. Linter could catch if one of them is unused
}
While semantically equivalent to a named function we do not have to come up with a descriptive name for the function, nor can we call the block again, making unintended use "impossible".
I'd humbly suggest that this would be a nice addition to the Rust language.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no files, tests, or entry points. Start by reviewing the proposed syntax, examples, linked talk, and discussion, then determine whether the idea has a sufficiently defined design for an RFC. Done would require a resolved language-design proposal rather than a localized code change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100