Skip to content

Commit 2ae2c62

Browse files
MagnumOpus21Siva Prasad
authored and
Siva Prasad
committed
Updated libcore/macro.rs to note write macro can work in no_std setups
1 parent b0297f3 commit 2ae2c62

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/libcore/macros.rs

+28
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,34 @@ macro_rules! try {
349349
/// write!(&mut v, "s = {:?}", s).unwrap(); // uses io::Write::write_fmt
350350
/// assert_eq!(v, b"s = \"abc 123\"");
351351
/// ```
352+
353+
/// /// Note : This macro can be used in no_std setups as well
354+
/// /// In a no_std setup you are responsible for the
355+
/// /// implementation details of the components.
356+
357+
/// ```rust
358+
/// extern crate core;
359+
/// use core::fmt::Write;
360+
361+
/// #[derive(Debug)]
362+
/// struct Greetings<'a>{
363+
/// message : &'a str,
364+
/// }
365+
366+
367+
/// impl<'a> Write for Greetings<'a>{
368+
/// fn write_str(&mut self, _s: &str) -> core::fmt::Result {
369+
/// unimplemented!();
370+
/// }
371+
/// }
372+
373+
/// fn main(){
374+
/// let mut m = Greetings{message: ""};
375+
/// write!(&mut m, "Hello World").expect("Not written");
376+
/// }
377+
/// ```
378+
379+
352380
#[macro_export]
353381
#[stable(feature = "rust1", since = "1.0.0")]
354382
macro_rules! write {

0 commit comments

Comments
 (0)