pub struct Runtime { /* private fields */ }Expand description
The async runtime that drives futures to completion.
The runtime provides:
- Task spawning via
spawn()andblock_on(). - Blocking task support via
spawn_blocking(). - Timer support (when the
timefeature is enabled). - File I/O offloading (when the
fsfeature is enabled).
§Examples
ⓘ
let runtime = RuntimeBuilder::new().build().unwrap();
let value = runtime.block_on(async { 42 });
assert_eq!(value, 42);Implementations§
Source§impl Runtime
impl Runtime
Sourcepub fn spawn<T>(
&self,
future: impl Future<Output = T> + 'static,
) -> JoinHandle<T> ⓘwhere
T: 'static,
pub fn spawn<T>(
&self,
future: impl Future<Output = T> + 'static,
) -> JoinHandle<T> ⓘwhere
T: 'static,
Spawn a task on this runtime.
Returns a JoinHandle that can be awaited to get the task’s output.
Sourcepub async fn spawn_blocking<T, F>(&self, f: F) -> Result<T, SpawnBlockingError>
pub async fn spawn_blocking<T, F>(&self, f: F) -> Result<T, SpawnBlockingError>
Spawn a blocking task on this runtime’s thread pool.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Runtime
impl !Send for Runtime
impl !Sync for Runtime
impl !UnwindSafe for Runtime
impl Freeze 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