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

Itertools::format[_with] docs mention panic within logging macro #941

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
43 changes: 39 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2355,8 +2355,6 @@ pub trait Itertools: Iterator {
/// All elements are formatted (any formatting trait)
/// with `sep` inserted between each element.
///
/// **Panics** if the formatter helper is formatted more than once.
///
/// ```
/// use itertools::Itertools;
///
Expand All @@ -2365,6 +2363,26 @@ pub trait Itertools: Iterator {
/// format!("{:.2}", data.iter().format(", ")),
/// "1.10, 2.72, -3.00");
/// ```
///
/// # Panics
/// When the formatter helper is formatted more than once.
///
/// <div class="warning">This can happen unexpectedly and be hard to debug if used in
/// <i>macros of some logging frameworks</i> like <code>tracing</code>!</div>
Copy link
Member

Choose a reason for hiding this comment

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

Instead of <code>tracing</code>, let's link to https://docs.rs/tracing

///
/// ```should_panic
/// # macro_rules! tracing_info {
/// # ($s:literal, $arg0:expr) => {
/// # let arg = $arg0;
/// # let _1 = format!($s, arg);
/// # let _2 = format!($s, arg);
/// # };
/// # }
/// use itertools::Itertools;
///
/// let data = [1.1, 2.71828, -3.];
/// tracing_info!("values: {:.2}", data.iter().format(", "));
/// ```
fn format(self, sep: &str) -> Format<Self>
where
Self: Sized,
Expand All @@ -2383,8 +2401,6 @@ pub trait Itertools: Iterator {
/// Using `&format_args!(...)` is the most versatile way to apply custom
/// element formatting. The callback can be called multiple times if needed.
///
/// **Panics** if the formatter helper is formatted more than once.
///
/// ```
/// use itertools::Itertools;
///
Expand All @@ -2401,8 +2417,27 @@ pub trait Itertools: Iterator {
/// });
/// assert_eq!(format!("{}", matrix_formatter),
/// "1, 2, 3\n4, 5, 6");
/// ```
///
/// # Panics
/// When the formatter helper is formatted more than once.
///
/// <div class="warning">This can happen unexpectedly and be hard to debug if used in
/// <i>macros of some logging frameworks</i> like <code>tracing</code>!</div>
///
/// ```should_panic
/// # macro_rules! tracing_info {
/// # ($s:literal, $arg0:expr) => {
/// # let arg = $arg0;
/// # let _1 = format!($s, arg);
/// # let _2 = format!($s, arg);
/// # };
/// # }
/// use itertools::Itertools;
///
/// let data = [1.1, 2.71828, -3.];
/// let data_formatter = data.iter().format_with(", ", |elt, f| f(&format_args!("{:.2}", elt)));
/// tracing_info!("values: {:.2}", data_formatter);
/// ```
fn format_with<F>(self, sep: &str, format: F) -> FormatWith<Self, F>
where
Expand Down
Loading