trap 0.2.1

Bare metal trapping.
Documentation

trap-rs

This library provides the trap function for aborting Rust programmes without the std crate.

Fundamentally, the goal of this crate is to allow for abnormal programme termination with more or less the guarantee that execution of the current code path will stop. Usually, std::process::abort is used for this, but on platforms or in crates without std, this is not possible.

Features

The std feature can be enabled to allow for raising the SIGABRT signal when calling trap. Furthermore, the nightly feature can be enabled for more architectural support in cases where the std crate isn't available.

Platform support

The following, target architectures have special code paths that do not yield infinite loops by default:

  • aarch64
  • arm
  • loongarch32
  • loongarch64
  • riscv32
  • riscv64
  • x86
  • x86_64

Additionally, with the nightly feature enabled, the following architectures are supported as well:

  • powerpc
  • powerpc64
  • sparc
  • sparc64
  • wasm32

Other targets will, by default, halt all execution in an infinite loop.

Copyright & Licence

Copyright © 2025 Gabriel Bjørnager Jensen.

trap-rs is distributed under either an MIT licence (see LICENCE-MIT.txt) or version 2.0 of the Apache License (see LICENCE-APACHE.txt), at your option.