1
Fork 0

Rollup merge of #139149 - mejrs:itaf, r=ehuss

unstable book: document import_trait_associated_functions

Documents https://github.com/rust-lang/rust/issues/134691 which was implemented in https://github.com/rust-lang/rust/pull/134754
This commit is contained in:
Matthias Krüger 2025-04-03 07:39:06 +02:00 committed by GitHub
commit ee56188457
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -0,0 +1,22 @@
# import_trait_associated_functions
The tracking issue for this feature is: [#134691]
[#134691]: https://github.com/rust-lang/rust/issues/134691
------------------------
This feature allows importing associated functions and constants from traits and then using them like regular items.
```rust
#![feature(import_trait_associated_functions)]
use std::ops::Add::add;
fn main() {
let numbers = vec![1, 2, 3, 4, 5, 6];
let sum = numbers.into_iter().reduce(add); // instead of `.reduce(Add:add)`
assert_eq!(sum, Some(21));
}
```