Skip to main content

Module runtime

Module runtime 

Source
Expand description

The Swift runtime’s own entry points, made safe to call.

crate::abi is about calling SwiftUI — the calling convention, metadata, witness tables. This module is about the runtime underneath it: the parts of libswiftCore a Swift program uses without ever naming them, because the compiler emits the calls. There is no compiler here, so they are called by hand.

Three groups, and they are here together because each is the same kind of thing — a runtime service a Rust caller has no other way to reach:

  • Dynamic casts. as? and as!, and the twenty other entry points behind them. What makes this worth having is that a ViewHandle carries its metadata at run time, so “is this really a Text?” is a question that can be asked rather than tracked.
  • Errors. A Swift Error is a box, swift_allocError makes one, and a Rust type can be the thing inside it once its Error conformance is synthesised. That is what lets Rust hand an error to Swift.
  • Tasks. detached runs a Rust closure as a real Swift Task, on Swift’s own global executor, with cancellation visible from both sides. crate::asyncfn supplies the async closures SwiftUI’s .task takes; this starts one from nothing.

Everything here is declared in swift-runtime-sys; what this adds is the safety argument, the ownership rules, and tests that the calls do what they are supposed to.

Structs§

CurrentTask
The task running right now — borrowed, not owned.
SwiftError
A Swift Error box, owned.
Task
A Swift Task this crate started, and owns.

Functions§

cast_class⚠
Cast a class reference to another class, or None.
cast_metatype⚠
Cast a metatype to another metatype, or None.
current_task
The task running right now, if any.
detached
Run body as a detached Swift Task, at the default priority.
detached_with_priority
Run body as a detached Swift Task at a chosen priority.
error_code
An Error holding one Int, for the cases that only need to say which.
is_type⚠
Is value of type target?
view_is
Is the view a T, where T is named by its mangled type?