mi piacerebbe scrivere questo:Tornando un'interfaccia Iterator più semplice invece di una mappa a Rust
fn fibs() -> std::iter::Iterator<int> {
return std::iter::iterate((1i, 1i), |(a, b)| { (b, a + b) }).map(|(a, _)| a)
}
Ma se lo faccio, ottengo questo errore:
error: explicit lifetime bound required
fn fibs() -> std::iter::Iterator<int> {
^^^^^^^^^^^^^^^^^^^^^^^^
Se, invece ho scrivere l'interfaccia completa, compila:
fn fibs() -> std::iter::Map<'static, (int, int), int, std::iter::Iterate<'static, (int, int)>> {
return std::iter::iterate((1i, 1i), |(a, b)| { (b, a + b) }).map(|(a, _)| a)
}
C'è un modo per restituire l'interfaccia più semplice?
Iterator è una caratteristica e non un tipo. Non so molto di Rust, ma penso che tu abbia bisogno di metterlo nella scatola. Per restituire i tipi astratti non archiviati abbiamo bisogno di questo: https://github.com/rust-lang/rfcs/pull/105 – Simon