Skip to content

Commit

Permalink
fix doctest (openzfs#287)
Browse files Browse the repository at this point in the history
`cargo test` runs both the explicit tests and any code in doc comments
that is not explicitly ignored.  There are some failures in
lazy_static_ptr.rs and vec_ext.rs, which this commit fixes by making the
example code actually runnable.
  • Loading branch information
ahrens authored Mar 12, 2022
1 parent 3956135 commit 457aa33
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
19 changes: 9 additions & 10 deletions cmd/zfs_object_agent/util/src/lazy_static_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ pub use paste::paste;
///
/// For example:
/// ```
/// lazy_static_ptr! {
/// pub static ref STRINGS: Mutex<Vec<String>> = Default::default();
/// util::lazy_static_ptr! {
/// pub static ref STRINGS: std::sync::Mutex<Vec<String>> = Default::default();
/// }
/// ```
/// This will declare a `pub static` variable named `STRINGS` which will deref to a
/// `Box<Mutex<Vec<String>>>`, similar to lazy_static!. Additionally, it will declare
/// ```
/// ```ignore
/// static STRINGS_PTR: AtomicPtr<Mutex<Vec<String>>> = ...;
/// ```
/// When `STRINGS` is initialized (on first dereference, or the .initialize() method),
Expand Down Expand Up @@ -127,14 +127,13 @@ impl<T> Drop for DebugPointerGuard<T> {
/// we are storing (but not dereferencing) a pointer to it. Typical use is combined with
/// `lazy_static_ptr!`:
/// ```
/// fn func(thing: Thing) {
/// lazy_static_ptr! {
/// static ref THINGS: DebugPointerSet<Thing> = Default::default();
/// }
/// let mut thing = THINGS.insert(thing);
/// // use `thing` as usual, it deref's to the passed in Thing
/// thing.method();
/// use util::lazy_static_ptr::DebugPointerSet;
/// util::lazy_static_ptr! {
/// static ref THINGS: DebugPointerSet<Vec<u64>> = Default::default();
/// }
/// let mut thing = THINGS.insert(Default::default());
/// // use `thing` as usual, it deref's to the passed in Thing
/// thing.push(42);
/// ```
/// Note that `lazy_static_ptr!` doesn't work well inside `async`
/// functions/methods/closures, because it's hard to name the variable in the
Expand Down
2 changes: 1 addition & 1 deletion cmd/zfs_object_agent/util/src/vec_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use more_asserts::*;
/// #[derivative(Debug)]
/// struct Foo {
/// #[derivative(Debug(format_with = "util::tersevec"))]
/// member: Vec<Bar>
/// member: Vec<u64>
/// }
/// ```
pub fn tersevec<E>(vec: &[E], fmt: &mut Formatter) -> Result {
Expand Down

0 comments on commit 457aa33

Please sign in to comment.