Skip to content

Commit 589db1f

Browse files
committed
Expand example to show how to implement qualified trait names
1 parent 3c8618f commit 589db1f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

library/core/src/macros/mod.rs

+17
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,23 @@ macro_rules! r#try {
474474
/// }
475475
/// ```
476476
///
477+
/// If you also need the trait names themselves, such as to implement one or both on your types,
478+
/// import the containing module and then name them with a prefix:
479+
///
480+
/// ```
481+
/// # #![allow(unused_imports)]
482+
/// use std::fmt::{self, Write as _};
483+
/// use std::io::{self, Write as _};
484+
///
485+
/// struct Example;
486+
///
487+
/// impl fmt::Write for Example {
488+
/// fn write_str(&mut self, _s: &str) -> core::fmt::Result {
489+
/// unimplemented!();
490+
/// }
491+
/// }
492+
/// ```
493+
///
477494
/// Note: This macro can be used in `no_std` setups as well.
478495
/// In a `no_std` setup you are responsible for the implementation details of the components.
479496
///

0 commit comments

Comments
 (0)