From 2ae2c628eec74b78d691c2df7a1eccbe9cbd0a72 Mon Sep 17 00:00:00 2001 From: MagnumOpus21 Date: Sat, 11 Aug 2018 14:43:50 -0400 Subject: [PATCH 1/7] Updated libcore/macro.rs to note write macro can work in no_std setups --- src/libcore/macros.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs index 0032bedc7ed1d..4bf5a6302bc4a 100644 --- a/src/libcore/macros.rs +++ b/src/libcore/macros.rs @@ -349,6 +349,34 @@ macro_rules! try { /// write!(&mut v, "s = {:?}", s).unwrap(); // uses io::Write::write_fmt /// assert_eq!(v, b"s = \"abc 123\""); /// ``` + +/// /// Note : This macro can be used in no_std setups as well +/// /// In a no_std setup you are responsible for the +/// /// implementation details of the components. + +/// ```rust +/// extern crate core; +/// use core::fmt::Write; + +/// #[derive(Debug)] +/// struct Greetings<'a>{ +/// message : &'a str, +/// } + + +/// impl<'a> Write for Greetings<'a>{ +/// fn write_str(&mut self, _s: &str) -> core::fmt::Result { +/// unimplemented!(); +/// } +/// } + +/// fn main(){ +/// let mut m = Greetings{message: ""}; +/// write!(&mut m, "Hello World").expect("Not written"); +/// } +/// ``` + + #[macro_export] #[stable(feature = "rust1", since = "1.0.0")] macro_rules! write { From 3ae6d06edbf57ce61a1f41e297dba750baf15ecb Mon Sep 17 00:00:00 2001 From: MagnumOpus21 Date: Sun, 12 Aug 2018 20:49:34 -0400 Subject: [PATCH 2/7] Refined the example --- src/libcore/macros.rs | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs index 4bf5a6302bc4a..2929fc9057d69 100644 --- a/src/libcore/macros.rs +++ b/src/libcore/macros.rs @@ -349,34 +349,22 @@ macro_rules! try { /// write!(&mut v, "s = {:?}", s).unwrap(); // uses io::Write::write_fmt /// assert_eq!(v, b"s = \"abc 123\""); /// ``` - -/// /// Note : This macro can be used in no_std setups as well -/// /// In a no_std setup you are responsible for the -/// /// implementation details of the components. - -/// ```rust -/// extern crate core; +/// Note : This macro can be used in no_std setups as well +/// In a no_std setup you are responsible for the +/// implementation details of the components. +/// ``` +/// # extern crate core; /// use core::fmt::Write; - -/// #[derive(Debug)] -/// struct Greetings<'a>{ -/// message : &'a str, +/// struct Example{ /// } - - -/// impl<'a> Write for Greetings<'a>{ +/// impl Write for Example{ /// fn write_str(&mut self, _s: &str) -> core::fmt::Result { /// unimplemented!(); /// } /// } - -/// fn main(){ -/// let mut m = Greetings{message: ""}; -/// write!(&mut m, "Hello World").expect("Not written"); -/// } +/// let mut m = Example{}; +/// write!(&mut m, "Hello World").expect("Not written"); /// ``` - - #[macro_export] #[stable(feature = "rust1", since = "1.0.0")] macro_rules! write { @@ -746,4 +734,4 @@ mod builtin { ($cond:expr,) => ({ /* compiler built-in */ }); ($cond:expr, $($arg:tt)+) => ({ /* compiler built-in */ }); } -} +} \ No newline at end of file From efb88b40a179a30118f8d75b54f007151bb7e4c8 Mon Sep 17 00:00:00 2001 From: MagnumOpus21 Date: Sun, 12 Aug 2018 22:17:30 -0400 Subject: [PATCH 3/7] Formatting errors rectified --- src/libcore/macros.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs index 2929fc9057d69..1d0ac42de6018 100644 --- a/src/libcore/macros.rs +++ b/src/libcore/macros.rs @@ -349,19 +349,24 @@ macro_rules! try { /// write!(&mut v, "s = {:?}", s).unwrap(); // uses io::Write::write_fmt /// assert_eq!(v, b"s = \"abc 123\""); /// ``` +/// /// Note : This macro can be used in no_std setups as well -/// In a no_std setup you are responsible for the +/// In a no_std setup you are responsible for the /// implementation details of the components. +/// /// ``` /// # extern crate core; /// use core::fmt::Write; +/// /// struct Example{ /// } +/// /// impl Write for Example{ /// fn write_str(&mut self, _s: &str) -> core::fmt::Result { /// unimplemented!(); /// } /// } +/// /// let mut m = Example{}; /// write!(&mut m, "Hello World").expect("Not written"); /// ``` @@ -734,4 +739,4 @@ mod builtin { ($cond:expr,) => ({ /* compiler built-in */ }); ($cond:expr, $($arg:tt)+) => ({ /* compiler built-in */ }); } -} \ No newline at end of file +} From 6c66aeb6c00a88e991b1e58247488394f0cac200 Mon Sep 17 00:00:00 2001 From: MagnumOpus21 Date: Mon, 13 Aug 2018 00:10:14 -0400 Subject: [PATCH 4/7] Prefixed no_run to the no_std write macro --- src/libcore/macros.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs index 1d0ac42de6018..6d7e1938cfde8 100644 --- a/src/libcore/macros.rs +++ b/src/libcore/macros.rs @@ -354,7 +354,7 @@ macro_rules! try { /// In a no_std setup you are responsible for the /// implementation details of the components. /// -/// ``` +/// ```no_run /// # extern crate core; /// use core::fmt::Write; /// From 94e8a6aa3bafa11b1cef8a5c206f56ca11826ffc Mon Sep 17 00:00:00 2001 From: MagnumOpus21 Date: Tue, 21 Aug 2018 12:32:59 -0400 Subject: [PATCH 5/7] Made the requested changes for Note: and no_std within backticks --- src/libcore/macros.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs index 6d7e1938cfde8..028b2c7658bf2 100644 --- a/src/libcore/macros.rs +++ b/src/libcore/macros.rs @@ -350,8 +350,8 @@ macro_rules! try { /// assert_eq!(v, b"s = \"abc 123\""); /// ``` /// -/// Note : This macro can be used in no_std setups as well -/// In a no_std setup you are responsible for the +/// Note: This macro can be used in no_std setups as well +/// In a `no_std` setup you are responsible for the /// implementation details of the components. /// /// ```no_run From 5e7039411b084bec5b75741b09c73ab177ddef7b Mon Sep 17 00:00:00 2001 From: MagnumOpus21 Date: Thu, 23 Aug 2018 19:21:54 -0400 Subject: [PATCH 6/7] Added a missing backtick to no std --- src/libcore/macros.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs index 028b2c7658bf2..ed07cf50b2279 100644 --- a/src/libcore/macros.rs +++ b/src/libcore/macros.rs @@ -350,7 +350,7 @@ macro_rules! try { /// assert_eq!(v, b"s = \"abc 123\""); /// ``` /// -/// Note: This macro can be used in no_std setups as well +/// Note: This macro can be used in `no_std` setups as well /// In a `no_std` setup you are responsible for the /// implementation details of the components. /// From 9d440d578d3ec724cae93d9fac3a2701724e780a Mon Sep 17 00:00:00 2001 From: Siva Prasad Date: Wed, 5 Sep 2018 09:09:50 -0400 Subject: [PATCH 7/7] Spacing changes made to the example --- src/libcore/macros.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs index ed07cf50b2279..a0c87f13e5d5a 100644 --- a/src/libcore/macros.rs +++ b/src/libcore/macros.rs @@ -355,20 +355,19 @@ macro_rules! try { /// implementation details of the components. /// /// ```no_run -/// # extern crate core; -/// use core::fmt::Write; +/// # extern crate core; +/// use core::fmt::Write; /// -/// struct Example{ -/// } +/// struct Example; /// -/// impl Write for Example{ -/// fn write_str(&mut self, _s: &str) -> core::fmt::Result { -/// unimplemented!(); -/// } -/// } +/// impl Write for Example { +/// fn write_str(&mut self, _s: &str) -> core::fmt::Result { +/// unimplemented!(); +/// } +/// } /// -/// let mut m = Example{}; -/// write!(&mut m, "Hello World").expect("Not written"); +/// let mut m = Example{}; +/// write!(&mut m, "Hello World").expect("Not written"); /// ``` #[macro_export] #[stable(feature = "rust1", since = "1.0.0")]