Skip to main content

Runtime

Struct Runtime 

Source
pub struct Runtime { /* private fields */ }
Expand description

The async runtime / 异步运行时

Main entry point for the async runtime. Manages scheduler, driver, and timers. 异步运行时的主入口点。管理调度器、驱动和定时器。

§Example / 示例

use hiver_runtime::Runtime;

fn main() -> std::io::Result<()> {
    let runtime = Runtime::new()?;
    runtime.block_on(async {
        println!("Hello, world!");
    });
    Ok(())
}

Implementations§

Source§

impl Runtime

Source

pub fn new() -> Result<Self>

Create a new runtime with default configuration 使用默认配置创建新的运行时

§Errors / 错误

Returns an error if runtime initialization fails. 如果运行时初始化失败则返回错误。

Source

pub fn builder() -> RuntimeBuilder

Create a runtime builder 创建运行时构建器

Source

pub fn with_config(config: RuntimeConfig) -> Result<Self>

Create a new runtime with the specified configuration 使用指定配置创建新的运行时

§Errors / 错误

Returns an error if: 返回错误如果:

  • Driver creation fails / Driver创建失败
  • Scheduler creation fails / 调度器创建失败
Source

pub fn block_on<F: Future<Output = ()>>(&mut self, future: F) -> Result<()>

Run a future to completion on this runtime 在此运行时上运行future到完成

This is the main entry point for executing async code. 这是执行异步代码的主入口点。

§Errors / 错误

Returns an error if the future returns an error. 如果future返回错误则返回错误。

§Example / 示例
use hiver_runtime::Runtime;

let runtime = Runtime::new().unwrap();
runtime.block_on(async {
    println!("Hello, world!");
});

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.