Skip to content

Commit

Permalink
Use #[doc = concat!()] in atomic integer docs (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e authored Aug 9, 2023
1 parent 6838e8e commit fa9eb42
Showing 1 changed file with 12 additions and 24 deletions.
36 changes: 12 additions & 24 deletions src/sync/atomic/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,23 @@ use super::Atomic;

use std::sync::atomic::Ordering;

// TODO: use `#[doc = concat!()]` directly once `extended_key_value_attributes` stable.
macro_rules! doc_comment {
($doc:expr, $($tt:tt)*) => {
#[doc = $doc]
$($tt)*
};
}

#[rustfmt::skip] // rustfmt cannot properly format multi-line concat!.
macro_rules! atomic_int {
($name: ident, $atomic_type: ty) => {
doc_comment! {
concat!(
" Mock implementation of `std::sync::atomic::", stringify!($name), "`.\n\n\
NOTE: Unlike `std::sync::atomic::", stringify!($name), "`, \
this type has a different in-memory representation than `",
stringify!($atomic_type), "`.",
),
#[derive(Debug)]
pub struct $name(Atomic<$atomic_type>);
}
#[doc = concat!(
" Mock implementation of `std::sync::atomic::", stringify!($name), "`.\n\n\
NOTE: Unlike `std::sync::atomic::", stringify!($name), "`, \
this type has a different in-memory representation than `",
stringify!($atomic_type), "`.",
)]
#[derive(Debug)]
pub struct $name(Atomic<$atomic_type>);

impl $name {
doc_comment! {
concat!(" Creates a new instance of `", stringify!($name), "`."),
#[track_caller]
pub fn new(v: $atomic_type) -> Self {
Self(Atomic::new(v, location!()))
}
#[doc = concat!(" Creates a new instance of `", stringify!($name), "`.")]
#[track_caller]
pub fn new(v: $atomic_type) -> Self {
Self(Atomic::new(v, location!()))
}

/// Get access to a mutable reference to the inner value.
Expand Down

0 comments on commit fa9eb42

Please sign in to comment.