Repeat string with integer multiplication

后端 未结 2 990
旧时难觅i
旧时难觅i 2021-01-03 17:21

Is there an easy way to do the following (from Python) in Rust?

>>> print (\"Repeat\" * 4) RepeatRepeatRepeatRepeat

I\'m starting to l

2条回答
  •  独厮守ぢ
    2021-01-03 18:05

    This one doesn't use Iterator::map but Iterator::fold instead:

    fn main() {
        println!("{:?}", (1..5).fold(String::new(), |b, _| b + "Repeat"));
    }
    

提交回复
热议问题