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?andas!, and the twenty other entry points behind them. What makes this worth having is that aViewHandlecarries its metadata at run time, so “is this really aText?” is a question that can be asked rather than tracked. - Errors. A Swift
Erroris a box,swift_allocErrormakes one, and a Rust type can be the thing inside it once itsErrorconformance is synthesised. That is what lets Rust hand an error to Swift. - Tasks.
detachedruns a Rust closure as a real SwiftTask, on Swift’s own global executor, with cancellation visible from both sides.crate::asyncfnsupplies the async closures SwiftUI’s.tasktakes; 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§
- Current
Task - The task running right now — borrowed, not owned.
- Swift
Error - A Swift
Errorbox, owned. - Task
- A Swift
Taskthis 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
bodyas a detached SwiftTask, at the default priority. - detached_
with_ priority - Run
bodyas a detached SwiftTaskat a chosen priority. - error_
code - An
Errorholding oneInt, for the cases that only need to say which. - is_type⚠
- Is
valueof typetarget? - view_is
- Is the view a
T, whereTis named by its mangled type?