2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Rangeを引数として受け取る

Last updated at Posted at 2022-04-27

impl Iterator<Item = usize>型として受け取る

fn func(range:impl Iterator<Item = usize>){
    for i in range{
        todo!();
    }
}

fn main(){
    func(0..10);
    func(0..=9);
}

0..100..=9で型が違うので単純にRange<usize>で受け取ろうとすると0..=9が受け取れなくなる。
ただ、このやり方だと当然Iterator<Item = usize>を実装してる型はなんでも受け取れてしまう(それが問題になることは無いと思うが)。

その他

ググって一番上に出てきたこれが思ってたのと違ったので。
https://qiita.com/hystcs/items/ed7911a1a0e6443ae40d

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?