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


Rust Iter用法及代碼示例

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

用法

pub struct Iter<'a, T: 'a> { /* fields omitted */ }

Receiver 上的消息的迭代器,由 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.iter() {
    println!("Got: {}", x);
}

相關用法


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