Skip to content

Commit b14262b

Browse files
authored
Merge pull request #62 from matklad/idioms
Modernize doc examples to use idiomatic Rust
2 parents 1645cdd + d41cc25 commit b14262b

File tree

5 files changed

+27
-19
lines changed

5 files changed

+27
-19
lines changed

.github/workflows/ci.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@ on: [push, pull_request]
44

55
jobs:
66
test:
7+
name: Test Suite
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
rust:
12+
- stable
13+
- beta
14+
- nightly
15+
steps:
16+
- uses: actions/checkout@v2
17+
- uses: actions-rs/toolchain@v1
18+
with:
19+
toolchain: ${{ matrix.rust }}
20+
override: true
21+
- name: Run cargo test
22+
run: cargo test
23+
24+
test-msrv:
725
name: Test Suite
826
runs-on: ubuntu-latest
927
strategy:
@@ -25,7 +43,9 @@ jobs:
2543
toolchain: ${{ matrix.rust }}
2644
override: true
2745
- name: Run cargo test
28-
run: cargo test
46+
# Exclude doctests here, as we don't want to clutter docs themselves
47+
# with backwards compatibility workarounds.
48+
run: cargo test --lib
2949

3050
nightly:
3151
name: Test Suite (nightly features)

README.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,9 @@ memoffset = "0.6"
2121

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

24-
Add the following lines at the top of your `main.rs` or `lib.rs` files.
25-
26-
```rust,ignore
27-
#[macro_use]
28-
extern crate memoffset;
29-
```
30-
3124
## Examples ##
3225
```rust
33-
#[macro_use]
34-
extern crate memoffset;
26+
use memoffset::{offset_of, span_of};
3527

3628
#[repr(C, packed)]
3729
struct Foo {

src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
//!
2525
//! ## Examples
2626
//! ```
27-
//! #[macro_use]
28-
//! extern crate memoffset;
27+
//! use memoffset::{offset_of, span_of};
2928
//!
3029
//! #[repr(C, packed)]
3130
//! struct HelpMeIAmTrappedInAStructFactory {
@@ -75,7 +74,7 @@ extern crate doc_comment;
7574
#[cfg(doctest)]
7675
doctest!("../README.md");
7776

78-
/// Hiden module for things the macros need to access.
77+
/// Hidden module for things the macros need to access.
7978
#[doc(hidden)]
8079
pub mod __priv {
8180
#[doc(hidden)]

src/offset_of.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ macro_rules! _memoffset_offset_from_unsafe {
7272
///
7373
/// ## Examples
7474
/// ```
75-
/// #[macro_use]
76-
/// extern crate memoffset;
75+
/// use memoffset::offset_of;
7776
///
7877
/// #[repr(C, packed)]
7978
/// struct Foo {
@@ -103,8 +102,7 @@ macro_rules! offset_of {
103102
///
104103
/// ## Examples
105104
/// ```
106-
/// #[macro_use]
107-
/// extern crate memoffset;
105+
/// use memoffset::offset_of_tuple;
108106
///
109107
/// fn main() {
110108
/// assert!(offset_of_tuple!((u8, u32), 1) >= 0, "Tuples do not have a defined layout");

src/span_of.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ macro_rules! _memoffset__compile_error {
5959
///
6060
/// ## Examples
6161
/// ```
62-
/// #[macro_use]
63-
/// extern crate memoffset;
62+
/// use memoffset::span_of;
6463
///
6564
/// #[repr(C)]
6665
/// struct Florp {

0 commit comments

Comments
 (0)