safina

Crates.iosafina
lib.rssafina
version0.7.0
created_at2020-12-01 07:20:18.177493+00
updated_at2025-07-01 02:45:43.71787+00
descriptionSafe async runtime
homepage
repositoryhttps://gitlab.com/leonhard-llc/safina-rs
max_upload_size
id318489
size262,834
Michael Leonhard (mleonhard)

documentation

README

crates.io version license: Apache 2.0 unsafe forbidden pipeline status

A safe Rust async runtime.

Features

  • forbid(unsafe_code)
  • Depends only on std at runtime
  • Good test coverage (>85%)
  • Decent performance: Task handling is 28% as fast as Tokio. See bench/.

Limitations

  • No fs module yet. async-fs is a fast async networking library that works well with Safina. It contains some unsafe code.
  • net module has poor performance. async-net is a fast async networking library that works well with Safina. It contains some unsafe code.

Benchmark

% cargo run --release --package bench
scheduler_bench_ms  tokio=9751
scheduler_bench_ms safina=7595
timer_bench_ms  tokio=765
timer_bench_ms safina=5045
mutex_bench_ms  tokio=782
mutex_bench_ms safina=4221
oneshot_bench_ms  tokio=673
oneshot_bench_ms safina=2511
bounded_channel_bench_ms  tokio=756
bounded_channel_bench_ms safina=2409
tcp_bench_ms  tokio=92
tcp_bench_ms safina=4153

Examples

use std::sync::Arc;
use safina::executor::Executor;

let executor: Arc<Executor> = Arc::default();
let (sender, receiver) = std::sync::mpsc::channel();
executor.spawn(async move {
    sender.send(()).unwrap();
});
receiver.recv().unwrap();
let result = safina::executor::block_on(async {
    prepare_request().await?;
    execute_request().await
})?;

Alternatives

  • smol
    • Popular
    • Contains some unsafe code
  • async-std
    • Very popular
    • Contains generous amounts of unsafe code
  • futures
    • Very popular
    • Contains generous amounts of unsafe code
  • tokio
    • Very popular
    • Fast
    • Internally extremely complicated
    • Full of unsafe code
  • bastion
    • Generous amounts of unsafe code
  • nostd_async

Cargo Geiger Safety Report


Metric output format: x/y
    x = unsafe code used by the build
    y = total unsafe code found in the crate

Symbols:
    🔒  = No `unsafe` usage found, declares #![forbid(unsafe_code)]
    ❓  = No `unsafe` usage found, missing #![forbid(unsafe_code)]
    ☢️  = `unsafe` usage found

Functions  Expressions  Impls  Traits  Methods  Dependency

0/0        0/0          0/0    0/0     0/0      🔒  safina 0.7.0
0/0        0/0          0/0    0/0     0/0      🔒  └── safina-macros 0.1.3
0/0        0/0          0/0    0/0     0/0      🔒      ├── safe-proc-macro2 1.0.95
0/0        0/0          0/0    0/0     0/0      🔒      │   └── unicode-xid 0.2.6
0/0        0/0          0/0    0/0     0/0      🔒      └── safe-quote 1.0.40
0/0        0/0          0/0    0/0     0/0      🔒          └── safe-proc-macro2 1.0.95

0/0        0/0          0/0    0/0     0/0

Changelog

Changelog
  • v0.7.0 2025-06-30
    • Require Rust 2024 edition.
    • Add [OptionAb::into_a], etc.
    • Threadpool queue is now unbounded, removed TryScheduleError::QueueFull.
    • [SyncSender] no longer requires Clone.
    • After Executor drops, silently discard new tasks and don't panic.
    • Add [Executor::get_thread_executor_weak].
  • v0.6.0 2024-11-02 - Simplify ExecutorBuilder.
  • v0.5.0 2024-10-27 - Add ExecutorBuilder and simplify Executor constructors.
  • v0.4.1 2024-10-27 - Improve async_test:
    • Make async_test a default feature so it shows up in docs.rs.
    • Timeout after 5s.
    • Override timeout with #[async_test(timeout_sec = 1)].
    • Support #[should_panic] and other test modifier macros.
    • Stop adding _ to the end of the test name.
  • v0.4.0 2024-10-26 - Merge crates into this crate.
  • v0.3.3 - Update docs.
  • v0.3.2 - Add threadpool module.
  • v0.3.1
    • Add sync_channel and SyncSender.
    • Add Receiver::async_recv to let users await without writing ugly (&mut receiver).await.
    • Remove Receiver::blocking and add try_recv, recv, etc.
  • v0.3.0
    • Move structs into sub-modules.
    • Replace Promise with oneshot, OneSender, and Receiver that supports async and blocking reads.
    • schedule_blocking to return new sync::Receiver.
  • v0.2.1 - Update docs.
  • v0.2.0
    • Executor::new and Executor::with_name to return Result.
    • ThreadPool::new to return Result.
    • ThreadPool::try_schedule to return an error when it fails to restart panicked threads.
    • ThreadPool::schedule to handle failure starting replacement threads.
  • v0.1.10 - block_on functions to take futures that are not Send.
  • v0.1.9 - Use once_cell by default.
  • v0.1.8 - Support stable with rust 1.51 and once_cell.
  • v0.1.7 - Add safina-net
  • v0.1.6 - Use safina-executor v0.1.3 API
  • v0.1.5 - Add safina::sync::Mutex
  • v0.1.4 - Upgrade to new safina-executor version which removes need for Box::pin.
  • v0.1.3 - Update docs
  • v0.1.2 - Renamed safina crate to safina-executor. Added new safina crate with re-exports, examples, and integration tests.
  • v0.1.1 - Add badges to readme
  • v0.1.0 - First published version

TO DO

  • Add init function that makes an executor and starts the timer thread.
  • Add an #[async_main] macro
  • safina::sync::unbounded_channel()

License: Apache-2.0

Commit count: 379

cargo fmt