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
impl Runtime
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Create a new runtime with default configuration 使用默认配置创建新的运行时
§Errors / 错误
Returns an error if runtime initialization fails. 如果运行时初始化失败则返回错误。
Sourcepub fn builder() -> RuntimeBuilder
pub fn builder() -> RuntimeBuilder
Create a runtime builder 创建运行时构建器
Sourcepub fn with_config(config: RuntimeConfig) -> Result<Self>
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 / 调度器创建失败
Sourcepub fn block_on<F: Future<Output = ()>>(&mut self, future: F) -> Result<()>
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§
impl !RefUnwindSafe for Runtime
impl !UnwindSafe for Runtime
impl Freeze for Runtime
impl Send for Runtime
impl Sync for Runtime
impl Unpin for Runtime
impl UnsafeUnpin for Runtime
Blanket Implementations§
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. Read more