Skip to content

zzmodules/runtime-assert

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

runtime-assert

Runtime asserts for ZZ

Installation

Add this to your zz.toml file:

[dependencies]
runtime_assert = "*"

[repos]
runtime_assert = "git+ssh://github.com/zzmodules/runtime-assert.git"

Usage

using runtime_assert

API

runtime_assert::assert(assertion)

Makes a runtime assertion. Upon failure, this function will call abort_signal::abort().

using runtime_assert::{ assert }

fn main() -> int {
  assert(false); // will abort here
  return 0;
}

Catching assertion errors

An abort signal callback function handler can be set to catch errors.

using abort_signal::{ set_abort_callback }
using log
using runtime_assert::{ assert }

static usize mut aborts = 0;

fn onabort() {
  aborts++;
}

fn main() -> int {
  set_abort_callback(onabort);

  assert(false);
  assert(false);
  assert(false);

  log::info("fails = %lu", aborts); // 3
  return 0;
}

See Also

License

MIT

Releases

No releases published

Packages

No packages published

Languages