Skip to content

Instantly share code, notes, and snippets.

@huseyinyilmaz
Created November 21, 2019 00:45
Show Gist options
  • Save huseyinyilmaz/d0b1dcbfcedeaf0ac4de93b67004d761 to your computer and use it in GitHub Desktop.
Save huseyinyilmaz/d0b1dcbfcedeaf0ac4de93b67004d761 to your computer and use it in GitHub Desktop.
#![feature(impl_trait_in_bindings)]
fn iter_returner<'a>(names: Vec<&'a str>) -> impl Iterator<Item=String> + 'a {
let it = names.into_iter()
.map(|n| format!("hello {}", n))
.map(String::from);
it
}
fn main() {
let i: impl Iterator<Item=String> = iter_returner(vec!["name1", "name2", "name3"]);
println!("{}", i.collect());
}
// warning: the feature `impl_trait_in_bindings` is incomplete and may cause the compiler to crash
// --> test.rs:1:12
// |
// 1 | #![feature(impl_trait_in_bindings)]
// | ^^^^^^^^^^^^^^^^^^^^^^
// |
// = note: `#[warn(incomplete_features)]` on by default
// error[E0283]: type annotations needed: cannot resolve `_: std::iter::FromIterator<std::string::String>`
// --> test.rs:12:22
// |
// 12 | println!("{}", i.collect());
// | ^^^^^^^
// error: aborting due to previous error
// For more information about this error, try `rustc --explain E0283`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment