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:
commit
ee56188457
1 changed files with 22 additions and 0 deletions
|
@ -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));
|
||||
}
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue