Steam
trait
Stream
trait 与 Future
类似,但能在完成前返还(yield)多个值,与标准库中的 Iterator
类似:
一个常见的使用 Stream
的例子是 futures
库中通道的 Receiver
。每次 Sender
端发送一个值时,它就会返回一个 Some(val)
,并且会在 Sender
关闭且所有消息都接收后返还 None
:
Steam
traitStream
trait 与 Future
类似,但能在完成前返还(yield)多个值,与标准库中的 Iterator
类似:
一个常见的使用 Stream
的例子是 futures
库中通道的 Receiver
。每次 Sender
端发送一个值时,它就会返回一个 Some(val)
,并且会在 Sender
关闭且所有消息都接收后返还 None
: