@@ -2326,8 +2326,6 @@ pub trait Itertools: Iterator {
2326
2326
/// All elements are formatted (any formatting trait)
2327
2327
/// with `sep` inserted between each element.
2328
2328
///
2329
- /// **Panics** if the formatter helper is formatted more than once.
2330
- ///
2331
2329
/// ```
2332
2330
/// use itertools::Itertools;
2333
2331
///
@@ -2336,6 +2334,26 @@ pub trait Itertools: Iterator {
2336
2334
/// format!("{:.2}", data.iter().format(", ")),
2337
2335
/// "1.10, 2.72, -3.00");
2338
2336
/// ```
2337
+ ///
2338
+ /// # Panics
2339
+ /// When the formatter helper is formatted more than once.
2340
+ ///
2341
+ /// ⚠ This can happen unexpectedly and be hard to debug if used in
2342
+ /// _macros of some logging frameworks_ like `tracing`! ⚠
2343
+ ///
2344
+ /// ```should_panic
2345
+ /// # macro_rules! tracing_info {
2346
+ /// # ($s:literal, $arg0:expr) => {
2347
+ /// # let arg = $arg0;
2348
+ /// # let _1 = format!($s, arg);
2349
+ /// # let _2 = format!($s, arg);
2350
+ /// # };
2351
+ /// # }
2352
+ /// use itertools::Itertools;
2353
+ ///
2354
+ /// let data = [1.1, 2.71828, -3.];
2355
+ /// tracing_info!("values: {:.2}", data.iter().format(", "));
2356
+ /// ```
2339
2357
fn format ( self , sep : & str ) -> Format < Self >
2340
2358
where
2341
2359
Self : Sized ,
@@ -2354,8 +2372,6 @@ pub trait Itertools: Iterator {
2354
2372
/// Using `&format_args!(...)` is the most versatile way to apply custom
2355
2373
/// element formatting. The callback can be called multiple times if needed.
2356
2374
///
2357
- /// **Panics** if the formatter helper is formatted more than once.
2358
- ///
2359
2375
/// ```
2360
2376
/// use itertools::Itertools;
2361
2377
///
@@ -2372,8 +2388,27 @@ pub trait Itertools: Iterator {
2372
2388
/// });
2373
2389
/// assert_eq!(format!("{}", matrix_formatter),
2374
2390
/// "1, 2, 3\n4, 5, 6");
2391
+ /// ```
2375
2392
///
2393
+ /// # Panics
2394
+ /// When the formatter helper is formatted more than once.
2395
+ ///
2396
+ /// ⚠ This can happen unexpectedly and be hard to debug if used in
2397
+ /// _macros of some logging frameworks_ like `tracing`! ⚠
2398
+ ///
2399
+ /// ```should_panic
2400
+ /// # macro_rules! tracing_info {
2401
+ /// # ($s:literal, $arg0:expr) => {
2402
+ /// # let arg = $arg0;
2403
+ /// # let _1 = format!($s, arg);
2404
+ /// # let _2 = format!($s, arg);
2405
+ /// # };
2406
+ /// # }
2407
+ /// use itertools::Itertools;
2376
2408
///
2409
+ /// let data = [1.1, 2.71828, -3.];
2410
+ /// let data_formatter = data.iter().format_with(", ", |elt, f| f(&format_args!("{:.2}", elt)));
2411
+ /// tracing_info!("values: {:.2}", data_formatter);
2377
2412
/// ```
2378
2413
fn format_with < F > ( self , sep : & str , format : F ) -> FormatWith < Self , F >
2379
2414
where
0 commit comments