From 209e9b9926d27ac71bc054bfdd48888e5d7d6d1a Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 7 Oct 2020 11:30:42 +0200 Subject: Shorten iterator chain hints --- crates/assists/src/utils.rs | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) (limited to 'crates/assists/src') diff --git a/crates/assists/src/utils.rs b/crates/assists/src/utils.rs index b341453d4..92b3c3b00 100644 --- a/crates/assists/src/utils.rs +++ b/crates/assists/src/utils.rs @@ -281,21 +281,34 @@ impl FamousDefs<'_, '_> { pub const FIXTURE: &'static str = r#"//- /libcore.rs crate:core pub mod convert { pub trait From { - fn from(T) -> Self; + fn from(t: T) -> Self; } } pub mod iter { pub use self::traits::{collect::IntoIterator, iterator::Iterator}; mod traits { - mod iterator { + pub(crate) mod iterator { use crate::option::Option; pub trait Iterator { type Item; fn next(&mut self) -> Option; + fn by_ref(&mut self) -> &mut Self { + self + } + fn take(self, n: usize) -> crate::iter::Take { + crate::iter::Take { inner: self } + } + } + + impl Iterator for &mut I { + type Item = I::Item; + fn next(&mut self) -> Option { + (**self).next() + } } } - mod collect { + pub(crate) mod collect { pub trait IntoIterator { type Item; } @@ -303,21 +316,35 @@ pub mod iter { } pub use self::sources::*; - mod sources { + pub(crate) mod sources { use super::Iterator; + use crate::option::Option::{self, *}; pub struct Repeat { element: A, } - pub fn repeat(elt: T) -> Repeat { + pub fn repeat(elt: T) -> Repeat { Repeat { element: elt } } - impl Iterator for Repeat { + impl Iterator for Repeat { type Item = A; fn next(&mut self) -> Option { - Some(self.element.clone()) + None + } + } + } + + pub use self::adapters::*; + pub(crate) mod adapters { + use super::Iterator; + use crate::option::Option::{self, *}; + pub struct Take { pub(crate) inner: I } + impl Iterator for Take where I: Iterator { + type Item = ::Item; + fn next(&mut self) -> Option<::Item> { + None } } } -- cgit v1.2.3