Skip to content

Commit

Permalink
Merge pull request #62 from matklad/idioms
Browse files Browse the repository at this point in the history
Modernize doc examples to use idiomatic Rust
  • Loading branch information
Gilnaa committed Nov 12, 2021
2 parents 1645cdd + d41cc25 commit b14262b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 19 deletions.
22 changes: 21 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@ on: [push, pull_request]

jobs:
test:
name: Test Suite
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
- beta
- nightly
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true
- name: Run cargo test
run: cargo test

test-msrv:
name: Test Suite
runs-on: ubuntu-latest
strategy:
Expand All @@ -25,7 +43,9 @@ jobs:
toolchain: ${{ matrix.rust }}
override: true
- name: Run cargo test
run: cargo test
# Exclude doctests here, as we don't want to clutter docs themselves
# with backwards compatibility workarounds.
run: cargo test --lib

nightly:
name: Test Suite (nightly features)
Expand Down
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,9 @@ memoffset = "0.6"

These versions will compile fine with rustc versions greater or equal to 1.19.

Add the following lines at the top of your `main.rs` or `lib.rs` files.

```rust,ignore
#[macro_use]
extern crate memoffset;
```

## Examples ##
```rust
#[macro_use]
extern crate memoffset;
use memoffset::{offset_of, span_of};

#[repr(C, packed)]
struct Foo {
Expand Down
5 changes: 2 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
//!
//! ## Examples
//! ```
//! #[macro_use]
//! extern crate memoffset;
//! use memoffset::{offset_of, span_of};
//!
//! #[repr(C, packed)]
//! struct HelpMeIAmTrappedInAStructFactory {
Expand Down Expand Up @@ -75,7 +74,7 @@ extern crate doc_comment;
#[cfg(doctest)]
doctest!("../README.md");

/// Hiden module for things the macros need to access.
/// Hidden module for things the macros need to access.
#[doc(hidden)]
pub mod __priv {
#[doc(hidden)]
Expand Down
6 changes: 2 additions & 4 deletions src/offset_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ macro_rules! _memoffset_offset_from_unsafe {
///
/// ## Examples
/// ```
/// #[macro_use]
/// extern crate memoffset;
/// use memoffset::offset_of;
///
/// #[repr(C, packed)]
/// struct Foo {
Expand Down Expand Up @@ -103,8 +102,7 @@ macro_rules! offset_of {
///
/// ## Examples
/// ```
/// #[macro_use]
/// extern crate memoffset;
/// use memoffset::offset_of_tuple;
///
/// fn main() {
/// assert!(offset_of_tuple!((u8, u32), 1) >= 0, "Tuples do not have a defined layout");
Expand Down
3 changes: 1 addition & 2 deletions src/span_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ macro_rules! _memoffset__compile_error {
///
/// ## Examples
/// ```
/// #[macro_use]
/// extern crate memoffset;
/// use memoffset::span_of;
///
/// #[repr(C)]
/// struct Florp {
Expand Down

0 comments on commit b14262b

Please sign in to comment.