blob: 782683b4f0413ca28bd733c49f263b46be47e1f5 [file] [log] [blame]
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Banner"><meta name="keywords" content="rust, rustlang, rust-lang, static_assertions"><title>static_assertions - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../normalize.css"><link rel="stylesheet" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../ayu.css" disabled><link rel="stylesheet" href="../dark.css" disabled><link rel="stylesheet" href="../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../storage.js"></script><script defer src="../crates.js"></script><script defer src="../main.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../favicon.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="sidebar-logo" href="../static_assertions/index.html"><div class="logo-container"><img src="https://raw.githubusercontent.com/nvzqz/static-assertions-rs/assets/Icon.png" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../static_assertions/index.html"><div class="logo-container">
<img src="https://raw.githubusercontent.com/nvzqz/static-assertions-rs/assets/Icon.png" alt="logo"></div></a><h2 class="location"><a href="#">Crate static_assertions</a></h2><div class="sidebar-elems"><ul class="block"><li class="version">Version 1.1.0</li><li><a id="all-types" href="all.html">All Items</a></li></ul><section><ul class="block"><li><a href="#macros">Macros</a></li></ul></section></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../wheel.svg"></a></div></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Crate <a class="mod" href="#">static_assertions</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../src/static_assertions/lib.rs.html#1-97">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p><a href="https://github.com/nvzqz/static-assertions-rs"><img src="https://raw.githubusercontent.com/nvzqz/static-assertions-rs/assets/Banner.png" alt="Banner" /></a></p>
<div align="center">
<a href="https://crates.io/crates/static_assertions">
<img src="https://img.shields.io/crates/d/static_assertions.svg" alt="Downloads">
</a>
<a href="https://travis-ci.org/nvzqz/static-assertions-rs">
<img src="https://travis-ci.org/nvzqz/static-assertions-rs.svg?branch=master" alt="Build Status">
</a>
<img src="https://img.shields.io/badge/rustc-^1.37.0-blue.svg" alt="rustc ^1.37.0">
<br><br>
</div>
<p>Assertions to ensure correct assumptions about constants, types, and more.</p>
<p><em>All</em> checks provided by this crate are performed at <a href="https://en.wikipedia.org/wiki/Compile_time">compile-time</a>. This
allows for finding errors quickly and early when it comes to ensuring
certain features or aspects of a codebase. These macros are especially
important when exposing a public API that requires types to be the same size
or implement certain traits.</p>
<h2 id="usage"><a href="#usage">Usage</a></h2>
<p>This crate is available <a href="https://crates.io/crates/static_assertions">on crates.io</a> and can be used by adding the
following to your project’s <a href="https://doc.rust-lang.org/cargo/reference/manifest.html"><code>Cargo.toml</code></a>:</p>
<div class="example-wrap"><pre class="language-toml"><code>[dependencies]
static_assertions = &quot;1.1.0&quot;</code></pre></div>
<p>and this to your crate root (<code>main.rs</code> or <code>lib.rs</code>):</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#[macro_use]
</span><span class="kw">extern crate </span>static_assertions;</code></pre></div>
<p>When using <a href="https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html#rust-2018">Rust 2018 edition</a>, the following shorthand can help if
having <code>#[macro_use]</code> is undesirable.</p>
<div class="example-wrap edition"><div class='tooltip' data-edition="2018"></div><pre class="rust rust-example-rendered"><code><span class="kw">extern crate </span>static_assertions <span class="kw">as </span>sa;
<span class="macro">sa::const_assert!</span>(<span class="bool-val">true</span>);</code></pre></div>
<h2 id="examples"><a href="#examples">Examples</a></h2>
<p>Very thorough examples are provided in the docs for
<a href="#macros">each individual macro</a>. Failure case examples are also documented.</p>
<h2 id="changes"><a href="#changes">Changes</a></h2>
<p>See <a href="https://github.com/nvzqz/static-assertions-rs/blob/master/CHANGELOG.md"><code>CHANGELOG.md</code></a>
for an exhaustive list of what has changed from one version to another.</p>
<h2 id="donate"><a href="#donate">Donate</a></h2>
<p>This project is made freely available (as in free beer), but unfortunately
not all beer is free! So, if you would like to buy me a beer (or coffee or
<em>more</em>), then consider supporting my work that’s benefited your project
and thousands of others.</p>
<a href="https://www.patreon.com/nvzqz">
<img src="https://c5.patreon.com/external/logo/become_a_patron_button.png" alt="Become a Patron!" height="35">
</a>
<a href="https://www.paypal.me/nvzqz">
<img src="https://buymecoffee.intm.org/img/button-paypal-white.png" alt="Buy me a coffee" height="35">
</a>
</div></details><h2 id="macros" class="small-section-header"><a href="#macros">Macros</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.assert_cfg.html" title="static_assertions::assert_cfg macro">assert_cfg</a></div><div class="item-right docblock-short">Asserts that a given configuration is set.</div></div><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.assert_eq_align.html" title="static_assertions::assert_eq_align macro">assert_eq_align</a></div><div class="item-right docblock-short">Asserts that types are equal in alignment.</div></div><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.assert_eq_size.html" title="static_assertions::assert_eq_size macro">assert_eq_size</a></div><div class="item-right docblock-short">Asserts that types are equal in size.</div></div><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.assert_eq_size_ptr.html" title="static_assertions::assert_eq_size_ptr macro">assert_eq_size_ptr</a></div><div class="item-right docblock-short">Asserts that values pointed to are equal in size.</div></div><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.assert_eq_size_val.html" title="static_assertions::assert_eq_size_val macro">assert_eq_size_val</a></div><div class="item-right docblock-short">Asserts that values are equal in size.</div></div><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.assert_fields.html" title="static_assertions::assert_fields macro">assert_fields</a></div><div class="item-right docblock-short">Asserts that the type has the given fields.</div></div><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.assert_impl_all.html" title="static_assertions::assert_impl_all macro">assert_impl_all</a></div><div class="item-right docblock-short">Asserts that the type implements <em>all</em> of the given traits.</div></div><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.assert_impl_any.html" title="static_assertions::assert_impl_any macro">assert_impl_any</a></div><div class="item-right docblock-short">Asserts that the type implements <em>any</em> of the given traits.</div></div><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.assert_impl_one.html" title="static_assertions::assert_impl_one macro">assert_impl_one</a></div><div class="item-right docblock-short">Asserts that the type implements exactly one in a set of traits.</div></div><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.assert_not_impl_all.html" title="static_assertions::assert_not_impl_all macro">assert_not_impl_all</a></div><div class="item-right docblock-short">Asserts that the type does <strong>not</strong> implement <em>all</em> of the given traits.</div></div><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.assert_not_impl_any.html" title="static_assertions::assert_not_impl_any macro">assert_not_impl_any</a></div><div class="item-right docblock-short">Asserts that the type does <strong>not</strong> implement <em>any</em> of the given traits.</div></div><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.assert_obj_safe.html" title="static_assertions::assert_obj_safe macro">assert_obj_safe</a></div><div class="item-right docblock-short">Asserts that the traits support dynamic dispatch
(<a href="https://doc.rust-lang.org/book/ch17-02-trait-objects.html#object-safety-is-required-for-trait-objects">object-safety</a>).</div></div><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.assert_trait_sub_all.html" title="static_assertions::assert_trait_sub_all macro">assert_trait_sub_all</a></div><div class="item-right docblock-short">Asserts that the trait is a child of all of the other traits.</div></div><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.assert_trait_super_all.html" title="static_assertions::assert_trait_super_all macro">assert_trait_super_all</a></div><div class="item-right docblock-short">Asserts that the trait is a parent of all of the other traits.</div></div><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.assert_type_eq_all.html" title="static_assertions::assert_type_eq_all macro">assert_type_eq_all</a></div><div class="item-right docblock-short">Asserts that <em>all</em> types in a list are equal to each other.</div></div><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.assert_type_ne_all.html" title="static_assertions::assert_type_ne_all macro">assert_type_ne_all</a></div><div class="item-right docblock-short">Asserts that <em>all</em> types are <strong>not</strong> equal to each other.</div></div><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.const_assert.html" title="static_assertions::const_assert macro">const_assert</a></div><div class="item-right docblock-short">Asserts that constant expressions evaluate to <code>true</code>.</div></div><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.const_assert_eq.html" title="static_assertions::const_assert_eq macro">const_assert_eq</a></div><div class="item-right docblock-short">Asserts that constants are equal in value.</div></div><div class="item-row"><div class="item-left module-item"><a class="macro" href="macro.const_assert_ne.html" title="static_assertions::const_assert_ne macro">const_assert_ne</a></div><div class="item-right docblock-short">Asserts that constants are <strong>not</strong> equal in value.</div></div></div></section></div></main><div id="rustdoc-vars" data-root-path="../" data-current-crate="static_assertions" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html>