tpt-torus-core
The Virtual Torus abstraction for TPT Torus — a unified, cross-platform asynchronous I/O framework that abstracts Linux io_uring, Windows IOCP, and macOS/BSD kqueue behind one ring-buffer API.
This crate is the public-facing heart of Torus. It is OS-agnostic: it defines the submission/completion model, the safe buffer-leasing API, and the Backend trait that every platform engine implements. You pair it with a backend crate for your target OS.
Key concepts
Torus— the thread-safe context object (shareable viaArc). Owns a virtualSubmissionRing/CompletionRingpair and delegates real I/O to aMutex<Box<dyn Backend>>.Flow— a submission: wraps anOperation(read/write/accept/connect/recv/send/close/readv/writev) plususer_data. Replaces a raw SQE.Result(TorusResult) — a completion: carries the result code and the submittinguser_data. Replaces a raw CQE.Backendtrait — the seam every OS engine implements (submit,reap,wait,in_flight, buffer registration).- Safe API —
LeaseRegistrytracks registered memory regions;TorusPanicdeliberately aborts on lease violations instead of letting a bad pointer reach the kernel. async_api::TorusAsync— high-levelasync/awaitwrapper with per-operation futures (ReadFuture,WriteFuture, …).TorusPool— a round-robin pool ofTorusinstances for concurrency across multiple backends/rings.
Installation
[]
= "0.1.0"
Backends are separate crates. Pick the one for your platform:
| Platform | Backend crate |
|---|---|
| Linux | tpt-torus-backend-uring |
| Windows | tpt-torus-backend-iocp |
| macOS/BSD | tpt-torus-backend-kqueue |
Quick start
use ;
use UringBackend;
let backend = new.expect;
let torus = new.expect;
let mut buf = vec!;
let flow = new;
torus.submit.expect;
torus.wait.expect;
let mut results = Vecnew;
torus.reap.expect;
# drop;
Safe API (Buffer Leasing)
Memory safety is enforced at the framework level. Register buffers before use so Torus can verify every I/O touches a tracked region:
use LeaseRegistry;
use Torus;
#
# let torus = make_torus;
let registry = new;
let mut buf = vec!;
unsafe ;
// Enable kernel fixed-buffer (zero-copy) I/O on io_uring:
torus.register_leases.ok;
A violation (out-of-bounds / overlapping / in-flight access) is converted into a TorusPanic that aborts the process deliberately — never letting a bad pointer reach the kernel.
Features
| Feature | Effect |
|---|---|
tracing |
Emits tracing spans/events for submission, completion, and lease activity. |
Relationship to other crates
tpt-torus-sys → tpt-torus-core → { backends, torus-rs, tpt-torus-cxx, tpt-torus-hw }
torus-rs is a batteries-included facade that re-exports this crate's entire API and adds a platform-aware open() helper. tpt-torus-cxx and tpt-torus-hw build on top of it.
Building & testing
License
Licensed under either of MIT or Apache License, Version 2.0 at your option.