From d228721809922421e59a647558324124168d8356 Mon Sep 17 00:00:00 2001 From: Tanish-Eagle Date: Wed, 21 Sep 2022 22:45:38 +0530 Subject: [PATCH 1/3] Fixed missing semicolons, and grammar mistakes --- en/src/formatted-output/formatting.md | 48 +++++++++++++-------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/en/src/formatted-output/formatting.md b/en/src/formatted-output/formatting.md index d4b7daf..8036939 100644 --- a/en/src/formatted-output/formatting.md +++ b/en/src/formatted-output/formatting.md @@ -1,4 +1,4 @@ -# formating +# Formatting ## Positional arguments @@ -6,7 +6,7 @@ ```rust,editable /* Fill in the blanks */ fn main() { - println!("{0}, this is {1}. {1}, this is {0}", "Alice", "Bob");// => Alice, this is Bob. Bob, this is Alice + println!("{0}, this is {1}. {1}, this is {0}", "Alice", "Bob"); // => Alice, this is Bob. Bob, this is Alice assert_eq!(format!("{1}{0}", 1, 2), __); assert_eq!(format!(__, 1, 2), "2112"); println!("Success!"); @@ -25,10 +25,10 @@ fn main() { assert_eq!(format!(__,a = "a", b = 'b', c = 3 ), "a 3 b"); /* Fix the error */ - // named argument must be placed after other arguments + // Named argument must be placed after other arguments println!("{abc} {1}", abc = "def", 2); - println!("Success!") + println!("Success!"); } ``` @@ -37,7 +37,7 @@ fn main() { 3.🌟🌟 By default, you can pad string with spaces ```rust,editable fn main() { - // the following two are padding with 5 spaces + // The following two are padding with 5 spaces println!("Hello {:5}!", "x"); // => "Hello x !" println!("Hello {:1$}!", "x", 5); // => "Hello x !" @@ -45,24 +45,24 @@ fn main() { assert_eq!(format!("Hello __!", 5, "x"), "Hello x !"); assert_eq!(format!("Hello __!", "x", width = 5), "Hello x !"); - println!("Success!") + println!("Success!"); } ``` 4.🌟🌟🌟 Left align, right align, pad with specified characters. ```rust,editable fn main() { - // left align + // Left align println!("Hello {:<5}!", "x"); // => Hello x ! - // right align + // Right align assert_eq!(format!("Hello __!", "x"), "Hello x!"); - // center align + // Center align assert_eq!(format!("Hello __!", "x"), "Hello x !"); - // left align, pad with '&' + // Left align, pad with '&' assert_eq!(format!("Hello {:&<5}!", "x"), __); - println!("Success!") + println!("Success!"); } ``` @@ -78,10 +78,10 @@ fn main() { assert!(format!("{number:0>width$}", number=1, width=6) == __); println!("Success!") -} +;} ``` -## precision +## Precision 6.🌟🌟 Floating point precision ```rust,editable @@ -95,11 +95,11 @@ fn main() { assert_eq!(format!("__", v), "+3.14"); assert_eq!(format!("__", v), "3"); - println!("Success!") + println!("Success!"); } ``` -7.🌟🌟🌟 string length +7.🌟🌟🌟 String length ```rust,editable fn main() { let s = "Hello, world!"; @@ -108,11 +108,11 @@ fn main() { assert_eq!(format!("Hello __!", 3, "abcdefg"), "Hello abc!"); - println!("Success!") + println!("Success!"); } ``` -## binary, octal, hex +## Binary, octal, hex - format!("{}", foo) -> "3735928559" - format!("0x{:X}", foo) -> "0xDEADBEEF" @@ -126,15 +126,15 @@ fn main() { assert_eq!(format!("__", 27), "0x1b"); assert_eq!(format!("__", 27), "0x1B"); - println!("{:x}!", 27); // hex with no prefix => 1b + println!("{:x}!", 27); // Hex with no prefix => 1b - println!("{:#010b}", 27); // pad binary with 0, width = 10, => 0b00011011 + println!("{:#010b}", 27); // Pad binary with 0, width = 10, => 0b00011011 - println!("Success!") + println!("Success!"); } ``` -## Capture the environments +## Capture the environment 9.🌟🌟🌟 ```rust,editable fn get_person() -> String { @@ -168,15 +168,15 @@ fn main() { **Example** ```rust,editable fn main() { - // exponent + // Exponent println!("{:2e}", 1000000000); // => 1e9 println!("{:2E}", 1000000000); // => 1E9 - // pointer address + // Pointer address let v= vec![1, 2, 3]; println!("{:p}", v.as_ptr()); // => 0x600002324050 - // escape + // Escape println!("Hello {{}}"); // => Hello {} } ``` From b034aedf9df8a3a5cb6499a13c2d9de61d532211 Mon Sep 17 00:00:00 2001 From: Tanish-Eagle Date: Wed, 21 Sep 2022 23:47:36 +0530 Subject: [PATCH 2/3] Edited the println!.md --- en/src/formatted-output/println.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/en/src/formatted-output/println.md b/en/src/formatted-output/println.md index 515b687..f9e24b7 100644 --- a/en/src/formatted-output/println.md +++ b/en/src/formatted-output/println.md @@ -1,6 +1,6 @@ # println! and format! Printing is handled by a series of [`macros`][macros] defined in [`std::fmt`][fmt] -some of which include: +Some of which include: * `format!`: write formatted text to [`String`][string] * `print!`: same as `format!` but the text is printed to the console (io::stdout). @@ -8,8 +8,7 @@ some of which include: * `eprint!`: same as `format!` but the text is printed to the standard error (io::stderr). * `eprintln!`: same as `eprint!`but a newline is appended. -All parse text in the same fashion. As a plus, Rust checks formatting -correctness at compile time. +All parse text in the same fashion. As a plus, Rust checks format correctness at compile time. ## `format!` 1.🌟 From 523c1ddf4f795a512bcc858c18c7b74258ab6f11 Mon Sep 17 00:00:00 2001 From: Tanish-Eagle Date: Wed, 21 Sep 2022 23:54:22 +0530 Subject: [PATCH 3/3] Fixed spelling mistakes in debug-display.md --- en/src/formatted-output/debug-display.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/en/src/formatted-output/debug-display.md b/en/src/formatted-output/debug-display.md index d515cfe..e6f8243 100644 --- a/en/src/formatted-output/debug-display.md +++ b/en/src/formatted-output/debug-display.md @@ -77,7 +77,7 @@ Yeah, `Debug` is simple and easy to use. But sometimes we want to customize the Unlike `Debug`, there is no way to derive the implementation of the `Display` trait, we have to manually implement it. -Anotherthing to note: the placefolder for `Display` is `{}` not `{:?}`. +Another thing to note: the placefolder for `Display` is `{}` not `{:?}`. 4. 🌟🌟 ```rust,editable @@ -103,16 +103,16 @@ fn main() { assert_eq!(format!("{}",point), "Display: 3.3 + 7.2i"); assert_eq!(format!("{:?}",point), "Debug: Complex { real: 3.3, imag: 7.2 }"); - println!("Success!") + println!("Success!"); } ``` ### `?` operator -Implementing `fmt::Display` for a structure whose elements must be handled separately is triky. The problem is each `write!` generates a `fmt::Result` which must be handled in the same place. +Implementing `fmt::Display` for a structure whose elements must be handled separately is tricky. The problem is each `write!` generates a `fmt::Result` which must be handled in the same place. -Fortunately, Rust provides the `?` operator to help us eliminate some unnecessary codes for deaing with `fmt::Result`. +Fortunately, Rust provides the `?` operator to help us eliminate some unnecessary codes for dealing with `fmt::Result`. 5. 🌟🌟 ```rust,editable @@ -147,7 +147,7 @@ impl fmt::Display for List { fn main() { let v = List(vec![1, 2, 3]); assert_eq!(format!("{}",v), "[0: 1, 1: 2, 2: 3]"); - println!("Success!") + println!("Success!"); } ```