當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Rust IntoIter用法及代碼示例

本文簡要介紹rust語言中 Struct std::sync::mpsc::IntoIter 的用法。

用法

pub struct IntoIter<T> { /* fields omitted */ }

消息上的擁有迭代器std::sync::mpsc::Receiver, 由...製作接收者::into_iter.

每當調用 next 時,此迭代器將阻塞,等待新消息,如果相應通道已掛起,則將返回 None

例子

use std::sync::mpsc::channel;
use std::thread;

let (send, recv) = channel();

thread::spawn(move || {
    send.send(1u8).unwrap();
    send.send(2u8).unwrap();
    send.send(3u8).unwrap();
});

for x in recv.into_iter() {
    println!("Got: {}", x);
}

相關用法


注:本文由純淨天空篩選整理自rust-lang.org大神的英文原創作品 Struct std::sync::mpsc::IntoIter。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。