跳到主要内容

CtrlC

搜索

结构体 CtrlC 

Source
pub struct CtrlC { /* private fields */ }
展开描述

代表一个监听器,用于接收通过 SetConsoleCtrlHandler 发递给进程的 “ctrl-c” 通知。

此事件可以通过 CtrlCStream 转换为 Stream

对进程的通知会通知所有监听该事件的接收者。 此外,如果通知没有被迟速处理,那么它们会被合并。 这意味着如果连续接收到两个通知, 则监听器只会收到一个包含这两个通知的项目。

实现§

Source§

impl CtrlC

Source

pub async fn recv(&mut self) -> Option<()>

接收下一个信号通知事件。

虽然返回 Option<()>,但它仍然不会实际返回 None。 这是一个随机就暂开新的,去掉它会是个破坏性变更。

§示例
use tokio::signal::windows::ctrl_c;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut signal = ctrl_c()?;

    // Print whenever a CTRL-C event is received.
    for countdown in (0..3).rev() {
        signal.recv().await;
        println!("got CTRL-C. {} more to exit", countdown);
    }

    Ok(())
}
Source

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::CtrlC;

struct MyFuture {
    ctrl_c: CtrlC,
}

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_c.poll_recv(cx)
    }
}

Trait 实现§

Source§

impl Debug for CtrlC

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

使用给定的格式化器格式化此值。 更多信息

自动 Trait 实现§

§

impl Freeze for CtrlC

§

impl !RefUnwindSafe for CtrlC

§

impl Send for CtrlC

§

impl Sync for CtrlC

§

impl Unpin for CtrlC

§

impl UnsafeUnpin for CtrlC

§

impl !UnwindSafe for CtrlC

Blanket 实现§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. 更多信息
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. 更多信息
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. 更多信息
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

原样返回传入的参数。

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

调用 U::from(self)

也就是说,此转换的具体行为取决于 From<T> for U 的实现方式。

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

转换出错时返回的类型。
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

执行转换。
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

转换出错时返回的类型。
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

执行转换。