aboutsummaryrefslogtreecommitdiff
path: root/crates/assists/src/utils.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/assists/src/utils.rs')
-rw-r--r--crates/assists/src/utils.rs41
1 files changed, 34 insertions, 7 deletions
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<'_, '_> {
281 pub const FIXTURE: &'static str = r#"//- /libcore.rs crate:core 281 pub const FIXTURE: &'static str = r#"//- /libcore.rs crate:core
282pub mod convert { 282pub mod convert {
283 pub trait From<T> { 283 pub trait From<T> {
284 fn from(T) -> Self; 284 fn from(t: T) -> Self;
285 } 285 }
286} 286}
287 287
288pub mod iter { 288pub mod iter {
289 pub use self::traits::{collect::IntoIterator, iterator::Iterator}; 289 pub use self::traits::{collect::IntoIterator, iterator::Iterator};
290 mod traits { 290 mod traits {
291 mod iterator { 291 pub(crate) mod iterator {
292 use crate::option::Option; 292 use crate::option::Option;
293 pub trait Iterator { 293 pub trait Iterator {
294 type Item; 294 type Item;
295 fn next(&mut self) -> Option<Self::Item>; 295 fn next(&mut self) -> Option<Self::Item>;
296 fn by_ref(&mut self) -> &mut Self {
297 self
298 }
299 fn take(self, n: usize) -> crate::iter::Take<Self> {
300 crate::iter::Take { inner: self }
301 }
302 }
303
304 impl<I: Iterator> Iterator for &mut I {
305 type Item = I::Item;
306 fn next(&mut self) -> Option<I::Item> {
307 (**self).next()
308 }
296 } 309 }
297 } 310 }
298 mod collect { 311 pub(crate) mod collect {
299 pub trait IntoIterator { 312 pub trait IntoIterator {
300 type Item; 313 type Item;
301 } 314 }
@@ -303,21 +316,35 @@ pub mod iter {
303 } 316 }
304 317
305 pub use self::sources::*; 318 pub use self::sources::*;
306 mod sources { 319 pub(crate) mod sources {
307 use super::Iterator; 320 use super::Iterator;
321 use crate::option::Option::{self, *};
308 pub struct Repeat<A> { 322 pub struct Repeat<A> {
309 element: A, 323 element: A,
310 } 324 }
311 325
312 pub fn repeat<T: Clone>(elt: T) -> Repeat<T> { 326 pub fn repeat<T>(elt: T) -> Repeat<T> {
313 Repeat { element: elt } 327 Repeat { element: elt }
314 } 328 }
315 329
316 impl<A: Clone> Iterator for Repeat<A> { 330 impl<A> Iterator for Repeat<A> {
317 type Item = A; 331 type Item = A;
318 332
319 fn next(&mut self) -> Option<A> { 333 fn next(&mut self) -> Option<A> {
320 Some(self.element.clone()) 334 None
335 }
336 }
337 }
338
339 pub use self::adapters::*;
340 pub(crate) mod adapters {
341 use super::Iterator;
342 use crate::option::Option::{self, *};
343 pub struct Take<I> { pub(crate) inner: I }
344 impl<I> Iterator for Take<I> where I: Iterator {
345 type Item = <I as Iterator>::Item;
346 fn next(&mut self) -> Option<<I as Iterator>::Item> {
347 None
321 } 348 }
322 } 349 }
323 } 350 }