pub struct CtrlLogoff { /* private fields */ }展开描述
代表一个监听器,用于接收通过 SetConsoleCtrlHandler
发递给进程的 “ctrl-logoff” 通知。
对进程的通知会通知所有监听该事件的监听器。 此外,如果通知没有被迟速处理,那么它们会被合并。 这意味着如果连续接收到两个通知, 则监听器只会收到一个包含这两个通知的项目。
实现§
Source§impl CtrlLogoff
impl CtrlLogoff
Sourcepub async fn recv(&mut self) -> Option<()>
pub async fn recv(&mut self) -> Option<()>
接收下一个信号通知事件。
虽然返回 Option<()>,但它仍然不会实际返回 None。
这是一个随机就暂开新的,去掉它会是个破坏性变更。
§示例
use tokio::signal::windows::ctrl_logoff;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// An listener of CTRL-LOGOFF events.
let mut signal = ctrl_logoff()?;
// Print whenever a CTRL-LOGOFF event is received.
signal.recv().await;
println!("got CTRL-LOGOFF. Cleaning up before exiting");
Ok(())
}Sourcepub fn poll_recv(&mut self, cx: &mut Context<'_>) -> Poll<Option<()>>
pub fn poll_recv(&mut self, cx: &mut Context<'_>) -> Poll<Option<()>>
在 async 上下文中轮询接收下一个信号通知事件。
虽然返回 Option<()>,但它仍然不会实际返回 None。
这是一个随机就暂开新的,去掉它会是个破坏性变更。
§示例
从手动实现的 future 中轮询
use std::pin::Pin;
use std::future::Future;
use std::task::{Context, Poll};
use tokio::signal::windows::CtrlLogoff;
struct MyFuture {
ctrl_logoff: CtrlLogoff,
}
impl Future for MyFuture {
type Output = Option<()>;
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
println!("polling MyFuture");
self.ctrl_logoff.poll_recv(cx)
}
}Trait 实现§
自动 Trait 实现§
impl Freeze for CtrlLogoff
impl !RefUnwindSafe for CtrlLogoff
impl Send for CtrlLogoff
impl Sync for CtrlLogoff
impl Unpin for CtrlLogoff
impl UnsafeUnpin for CtrlLogoff
impl !UnwindSafe for CtrlLogoff
Blanket 实现§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. 更多信息