-
Notifications
You must be signed in to change notification settings - Fork 567
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed available generic args for default impls, and lowering diagnost…
- Loading branch information
Showing
5 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
pub trait IteratorEx<T, impl I: Iterator<T>, +Destruct<T>, +Drop<I::Item>> { | ||
fn advance_by( | ||
ref self: T, n: usize, | ||
) -> Result< | ||
(), NonZero<usize>, | ||
> { | ||
let mut res = Result::Ok(()); | ||
for i in 0..n { | ||
if self.next().is_none() { | ||
res = Result::Err((n - i).try_into().unwrap()); | ||
break; | ||
} | ||
}; | ||
res | ||
} | ||
} | ||
impl ItratorExImpl<T, impl I: Iterator<T>, +Destruct<T>, +Drop<I::Item>> of IteratorEx<T, I> {} | ||
|
||
#[test] | ||
fn test_advance_by() { | ||
let mut iter = array![1_u8, 2, 3, 4].into_iter(); | ||
assert_eq!(iter.advance_by(2), Result::Ok(())); | ||
assert_eq!(iter.next(), Option::Some(3)); | ||
assert_eq!(iter.advance_by(0), Result::Ok(())); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
trait DefaultTraitImpl { | ||
fn call<T, F, +Drop<F>, impl func: core::ops::FnOnce<F, ()>[Output: T], +Drop<T>>(f: F) { | ||
f(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters