All Projects → nvzqz → Static Assertions Rs

nvzqz / Static Assertions Rs

Licence: other
Ensure correct assumptions about constants, types, and more in Rust

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Static Assertions Rs

nim-gatabase
Connection-Pooling Compile-Time ORM for Nim
Stars: ✭ 103 (-71.63%)
Mutual labels:  compile-time
php-assert
Fast flexible php assert
Stars: ✭ 18 (-95.04%)
Mutual labels:  assert
Strikt
An assertion library for Kotlin
Stars: ✭ 310 (-14.6%)
Mutual labels:  assert
ghostwriter
Solutions for instrumenting application flow tracking API calls into an existing code base in a non-invasive way
Stars: ✭ 17 (-95.32%)
Mutual labels:  compile-time
uninttp
A universal type for non-type template parameters for C++20 or later.
Stars: ✭ 16 (-95.59%)
Mutual labels:  compile-time
underscore.haz
🔍 _.haz() is like _.has() but this underscore and/or lodash mixin lets you do deep object key existence checking with a dot denoted string, for example 'a.b.c'
Stars: ✭ 13 (-96.42%)
Mutual labels:  assert
got
An enjoyable golang test framework.
Stars: ✭ 234 (-35.54%)
Mutual labels:  assert
Optimizing Swift Build Times
Collection of advice on optimizing compile times of Swift projects.
Stars: ✭ 3,509 (+866.67%)
Mutual labels:  compile-time
assert-true
A lot of ways to you set your assert as true
Stars: ✭ 19 (-94.77%)
Mutual labels:  assert
Commonjs Assert
Node.js's require('assert') for all engines
Stars: ✭ 255 (-29.75%)
Mutual labels:  assert
beast-dragon
Beast language compiler & reference
Stars: ✭ 13 (-96.42%)
Mutual labels:  compile-time
static-string-cpp
Compile-time string manipulation library for modern C++
Stars: ✭ 34 (-90.63%)
Mutual labels:  compile-time
Revisited
🧑‍🤝‍🧑 The visitor pattern revisited. An inheritance-aware acyclic visitor template, any and any-function templates.
Stars: ✭ 14 (-96.14%)
Mutual labels:  compile-time
compile-time-perf
Measures high-level timing and memory usage metrics during compilation
Stars: ✭ 64 (-82.37%)
Mutual labels:  compile-time
Trait Eval
We all know Rust's trait system is Turing complete, so tell me, why aren't we exploiting this???
Stars: ✭ 325 (-10.47%)
Mutual labels:  compile-time
earl
☕ Ergonomic, modern and type-safe assertion library for TypeScript
Stars: ✭ 217 (-40.22%)
Mutual labels:  assert
openapi-assert
Asserting data against OpenAPI docs.
Stars: ✭ 17 (-95.32%)
Mutual labels:  assert
Atrium
A multiplatform assertion library for Kotlin
Stars: ✭ 359 (-1.1%)
Mutual labels:  assert
Semimap
A semi compile-/run-time associative map container with compile-time lookup and run-time storage
Stars: ✭ 335 (-7.71%)
Mutual labels:  compile-time
Naza
🍀 Go basic library. || Go语言基础库
Stars: ✭ 253 (-30.3%)
Mutual labels:  assert

Banner

Compile-time assertions for Rust, brought to you by Nikolai Vazquez.

This library lets you ensure correct assumptions about constants, types, and more. See the docs and FAQ for more info!

Installation

This crate is available on crates.io and can be used by adding the following to your project's Cargo.toml:

[dependencies]
static_assertions = "1.1.0"

and this to your crate root (main.rs or lib.rs):

#[macro_use]
extern crate static_assertions;

Usage

This crate exposes the following macros:

FAQ

  • Q: When would I want to use this?

    A: This library is useful for when wanting to ensure properties of constants, types, and traits.

    Basic examples:

    • With the release of 1.39, str::len can be called in a const context. Using const_assert!, one can check that a string generated from elsewhere is of a given size:

      const DATA: &str = include_str!("path/to/string.txt");
      
      const_assert!(DATA.len() < 512);
      
    • Have a type that absolutely must implement certain traits? With assert_impl_all!, one can ensure this:

      struct Foo {
          value: // ...
      }
      
      assert_impl_all!(Foo: Send, Sync);
      
  • Q: How can I contribute?

    A: A couple of ways! You can:

    • Attempt coming up with some form of static analysis that you'd like to see implemented. Create a new issue and describe how you'd imagine your assertion to work, with example code to demonstrate.

    • Implement your own static assertion and create a pull request.

    • Give feedback. What are some pain points? Where is it unpleasant?

    • Write docs. If you're familiar with how this library works, sharing your knowledge with the rest its users would be great!

  • Q: Will this affect my compiled binary?

    A: Nope! There is zero runtime cost to using this because all checks are at compile-time, and so no code is emitted to run.

  • Q: Will this affect my compile times?

    A: Likely not by anything perceivable. If this is a concern, this library can be put in dev-dependencies:

    [dev-dependencies]
    static_assertions = "1.1.0"
    

    and then assertions can be conditionally run behind #[cfg(test)]:

    #[cfg(test)]
    const_assert_eq!(MEANING_OF_LIFE, 42);
    

    However, the assertions will only be checked when running cargo test. This somewhat defeats the purpose of catching false static conditions up-front with a compilation failure.

  • Q: What is const _?

    A: It's a way of creating an unnamed constant. This is used so that macros can be called from a global scope without requiring a scope-unique label. This library makes use of the side effects of evaluating the const expression. See the feature's tracking issue and issue #1 for more info.

Changes

See CHANGELOG.md for a complete list of what has changed from one version to another.

License

This project is released under either:

at your choosing.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].