Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve documentation #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
Compile-time assertions for Rust, brought to you by
[Nikolai Vazquez](https://twitter.com/NikolaiVazquez).

This library lets you ensure correct assumptions about constants, types, and
This library lets you ensure assumptions about constants, types, and
more. See the [docs] and [FAQ](#faq) for more info!

## Installation
Expand Down Expand Up @@ -70,12 +70,12 @@ This crate exposes the following macros:

- **Q:** When would I want to use this?

**A:** This library is useful for when wanting to ensure properties of
**A:** This library is useful 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`
- With the release of Rust 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:

Expand Down Expand Up @@ -114,7 +114,7 @@ This crate exposes the following macros:
- **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.
at compile-time, so no code is emitted to run.

- **Q:** Will this affect my compile times?

Expand Down
2 changes: 1 addition & 1 deletion src/assert_align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/// ```
///
/// The following example fails to compile because `i32x4` explicitly has 4
/// times the alignment as `[i32; 4]`:
/// times the alignment of `[i32; 4]`:
///
/// ```compile_fail
/// # #[macro_use] extern crate static_assertions; fn main() {}
Expand Down
4 changes: 2 additions & 2 deletions src/assert_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ macro_rules! assert_impl_any {
///
/// Note that the combination of all provided traits is required to not be
/// implemented. If you want to check that none of multiple traits are
/// implemented you should invoke [`assert_impl_not_any!`] instead.
/// implemented, you should invoke [`assert_impl_not_any!`] instead.
///
/// # Examples
///
Expand Down Expand Up @@ -233,7 +233,7 @@ macro_rules! assert_not_impl_all {
///
/// This macro causes a compilation failure if any of the provided individual
/// traits are implemented for the type. If you want to check that a combination
/// of traits is not implemented you should invoke [`assert_impl_not_all!`]
/// of traits is not implemented, you should invoke [`assert_impl_not_all!`]
/// instead. For single traits both macros behave the same.
///
/// # Examples
Expand Down
14 changes: 3 additions & 11 deletions src/assert_obj_safe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
/// Asserts that the traits support dynamic dispatch
/// ([object-safety](https://doc.rust-lang.org/book/ch17-02-trait-objects.html#object-safety-is-required-for-trait-objects)).
///
/// This is useful for when changes are made to a trait that accidentally
/// This is useful when changes are made to a trait that accidentally
/// prevent it from being used as an [object]. Such a case would be adding a
/// generic method and forgetting to add `where Self: Sized` after it. If left
/// generic method and forgetting to add `where Self: Sized`. If left
/// unnoticed, that mistake will affect crate users and break both forward and
/// backward compatibility.
///
Expand Down Expand Up @@ -36,14 +36,6 @@
/// assert_obj_safe!(inner::BasicTrait);
/// ```
///
/// The following example fails to compile because raw pointers cannot be sent
/// between threads safely:
///
/// ```compile_fail
/// # #[macro_use] extern crate static_assertions; fn main() {}
/// assert_impl!(*const u8, Send);
/// ```
///
/// The following example fails to compile because generics without
/// `where Self: Sized` are not allowed in [object-safe][object] trait methods:
///
Expand Down Expand Up @@ -71,6 +63,6 @@
#[macro_export]
macro_rules! assert_obj_safe {
($($xs:path),+ $(,)?) => {
$(const _: Option<&$xs> = None;)+
$(const _: Option<&dyn $xs> = None;)+
Comment on lines -74 to +66
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only a cosmetic change. The dyn syntax for trait objects exists since Rust 1.27 (the MSRV of this crate is 1.37) and the old syntax of just using the trait name is now deprecated.

};
}
10 changes: 5 additions & 5 deletions src/assert_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
///
/// # Alternatives
///
/// There also exists [`assert_size_eq_val`](macro.assert_size_eq_val.html) and
/// There also exist [`assert_size_eq_val`](macro.assert_size_eq_val.html) and
/// [`assert_size_eq_ptr`](macro.assert_size_eq_ptr.html). Instead of specifying
/// types to compare, values' sizes can be directly compared against each other.
///
Expand Down Expand Up @@ -39,7 +39,7 @@ macro_rules! assert_size_eq {
};
}

/// Asserts that types are equal in alignment.
/// Asserts that types are equal in size.
///
/// This macro has been deprecated in favor of
/// [`assert_size_eq!`](macro.assert_size_eq.html).
Expand All @@ -58,8 +58,8 @@ macro_rules! assert_eq_size {
///
/// # Examples
///
/// This especially is useful for when coercing pointers between different types
/// and ensuring the underlying values are the same size.
/// This especially is useful when coercing between pointers to different types
/// and ensuring the underlying values have the same size.
///
/// ```
/// # #[macro_use] extern crate static_assertions; fn main() {}
Expand Down Expand Up @@ -152,7 +152,7 @@ macro_rules! assert_size_eq_val {
}
}

/// Asserts that values pointed to are equal in size.
/// Asserts that values are equal in size.
///
/// This macro has been deprecated in favor of
/// [`assert_size_eq_val!`](macro.assert_size_eq_val.html).
Expand Down
8 changes: 4 additions & 4 deletions src/assert_trait.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// Asserts that the trait is a child of all of the other traits.
/// Asserts that the trait is a subtrait of all of the other traits.
///
/// Related:
/// - [`assert_trait_super_all!`]
Expand Down Expand Up @@ -43,14 +43,14 @@ macro_rules! assert_trait_sub_all {
};
}

/// Asserts that the trait is a parent of all of the other traits.
/// Asserts that the trait is a supertrait of all of the other traits.
///
/// Related:
/// - [`assert_trait_sub_all!`]
///
/// # Examples
///
/// With this, traits `A` and `B` can both be tested to require [`Copy`] on a
/// With this, traits `A` and `B` can both be tested to require [`Copy`] in a
/// single line:
///
/// ```
Expand Down Expand Up @@ -94,7 +94,7 @@ macro_rules! assert_trait_super_all {
};
}

/// Asserts that the trait is a child of one or more of the other traits.
/// Asserts that the trait is a subtrait of one or more of the other traits.
///
/// Related:
/// - [`assert_impl_any!`]
Expand Down
10 changes: 5 additions & 5 deletions src/const_assert.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/// Asserts that constant expressions evaluate to `true`.
///
/// Constant expressions can be ensured to have certain properties via this
/// macro If the expression evaluates to `false`, the file will fail to compile.
/// This is synonymous to [`static_assert` in C++][static_assert].
/// macro. If the expression evaluates to `false`, the module will fail to compile.
/// This is similar to [`static_assert` in C++][static_assert].
///
/// # Alternatives
///
/// There also exists [`const_assert_eq`](macro.const_assert_eq.html) for
/// There also exist [`const_assert_eq`](macro.const_assert_eq.html) for
/// validating whether a sequence of expressions are equal to one another.
///
/// # Examples
Expand Down Expand Up @@ -72,7 +72,7 @@ macro_rules! const_assert {
/// const_assert_eq!(TWO * TWO, TWO + TWO);
/// ```
///
/// Just because 2 × 2 = 2 + 2 doesn't mean it holds true for other numbers:
/// Just because 2 × 2 = 2 + 2, doesn't mean it holds true for other numbers:
///
/// ```compile_fail
/// # #[macro_use] extern crate static_assertions; fn main() {}
Expand Down Expand Up @@ -164,7 +164,7 @@ macro_rules! const_assert_gt {
};
}

/// Asserts that constants are less than or equal to each other.
/// Asserts that constants are greater than or equal to each other.
#[macro_export(local_inner_macros)]
macro_rules! const_assert_ge {
($x:expr, $($y:expr),+ $(,)?) => {
Expand Down
2 changes: 1 addition & 1 deletion src/does_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
///
/// # Examples
///
/// One can mimic `assert_impl!` using this macro:
/// One can mimic `assert_impl!` using the following:
///
/// ```
/// # #[macro_use] extern crate static_assertions; fn main() {}
Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! <br><br>
//! </div>
//!
//! Assertions to ensure correct assumptions about constants, types, and more.
//! Assertions to ensure assumptions about constants, types, and more.
//!
//! _All_ checks provided by this crate are performed at [compile-time]. This
//! allows for finding errors quickly and early when it comes to ensuring
Expand All @@ -38,19 +38,19 @@
//! # fn main() {}
//! ```
//!
//! When using [Rust 2018 edition][2018], the following shorthand can help if
//! When using the [Rust 2018 edition][2018], the following shorthand can help if
//! having `#[macro_use]` is undesirable.
//!
//! ```edition2018
//! extern crate static_assertions as sa;
//! use static_assertions::const_assert;
//!
//! sa::const_assert!(true);
//! const_assert!(true);
//! ```
//!
//! ## Procedural Extensions
//!
//! As an extension crate [`proc_static_assertions`] adds a number of new
//! assertions to this. These are implemented as [procedural macros], hence the
//! As an extension crate, [`proc_static_assertions`] adds a number of new
//! assertions. These are implemented as [procedural macros], hence the
//! "proc" prefix. As a result, they have a bit more visibility over what's
//! being asserted over than normal macros would.
//!
Expand Down