Produced | OSC Open Source Community (ID: oschina2013)
The team members responsible for Rust language features launched the Keyword Generics Initiative , which they say is to explore whether to add keyword generics to Rust .
"Initiative" is a term in Rust's governance model that, unlike "working group" and "team", has an ad hoc nature. "Initiative" exists to explore, design and implement specific work content. Once this work is over, the temporary "Initiative" will end.
According to reports, while Rust supports generics, there is no way to add generics to other common keyword-declared things . For example using the const
or async
function.
But "keyword generics" aren't just designed for asynchrony, the ultimate goal is to make them available for all modifier keywords -- including ones that may be defined in the future . Overall, they hope to fill that void with this exploration of "keyword generics": the ability to add generics to keywords like const
and async
.
async<A> trait Read {
async<A> fn read(&mut self, buf: &mut [u8]) -> Result<usize>;
async<A> fn read_to_string(&mut self, buf: &mut String) -> Result<usize> { ... }
}
async<A> fn read_to_string(reader: &mut impl Read * A) -> std::io::Result<String> {
let mut string = String::new();
reader.read_to_string(&mut string).await?;
string
}
There is no RFC document for "keyword generics" yet, and team members say it's in the "pre-RFC" stage. In addition, they also stated that for this feature, even if ensuring compatibility is one of the most difficult tasks, it will still maximize backward compatibility.
Related discussions:
Reddit : https://www.reddit.com/r/rust/comments/w9gi48/announcing_the_keyword_generics_initiative/
Lobsters: https://lobste.rs/s/hyd2sx/announcing_keyword_generics_initiative
Related Links:
https://blog.rust-lang.org/inside-rust/2022/07/27/keyword-generics.html
Here are the latest open source information, software updates, technical dry goods, etc.
Click here↓↓↓ Remember to follow ✔ Star ⭐ Oh~