From 9552f2a1fee55280b3bdda18624058aa14c1a369 Mon Sep 17 00:00:00 2001 From: Ay355 <77558710+Ay-355@users.noreply.github.com> Date: Mon, 1 Nov 2021 14:27:42 -0700 Subject: [rust/all] Remove .iter() on array example (#4230) As of Rust 1.53.0, arrays implement the IntoIterator trait, making .iter() on an array unnecessary --- rust.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rust.html.markdown') diff --git a/rust.html.markdown b/rust.html.markdown index e835de12..9cb44d04 100644 --- a/rust.html.markdown +++ b/rust.html.markdown @@ -236,7 +236,7 @@ fn main() { // `for` loops/iteration let array = [1, 2, 3]; - for i in array.iter() { + for i in array { println!("{}", i); } -- cgit v1.2.3 From e0f5bcf36a4eb27c72473ce5dbab960792e364cc Mon Sep 17 00:00:00 2001 From: Maximilian Sonnenburg <25778959+LamdaLamdaLamda@users.noreply.github.com> Date: Mon, 3 Jan 2022 18:16:59 +0100 Subject: [rust/en] Function pointer type added (#4107) * Function pointer type added * String slice details added. * String slice view explanation. --- rust.html.markdown | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'rust.html.markdown') diff --git a/rust.html.markdown b/rust.html.markdown index 9cb44d04..9e07e005 100644 --- a/rust.html.markdown +++ b/rust.html.markdown @@ -89,11 +89,16 @@ fn main() { println!("{} {}", f, x); // 1.3 hello world // A `String` – a heap-allocated string + // Stored as a `Vec` and always hold a valid UTF-8 sequence, + // which is not null terminated. let s: String = "hello world".to_string(); // A string slice – an immutable view into another string - // The string buffer can be statically allocated like in a string literal - // or contained in another object (in this case, `s`) + // This is basically an immutable pair of pointers to a string – it doesn’t + // actually contain the contents of a string, just a pointer to + // the begin and a pointer to the end of a string buffer, + // statically allocated or contained in another object (in this case, `s`). + // The string slice is like a view `&[u8]` into `Vec`. let s_slice: &str = &s; println!("{} {}", s, s_slice); // hello world hello world @@ -205,6 +210,21 @@ fn main() { let another_foo = Foo { bar: 1 }; println!("{:?}", another_foo.frobnicate()); // Some(1) + // Function pointer types // + + fn fibonacci(n: u32) -> u32 { + match n { + 0 => 1, + 1 => 1, + _ => fibonacci(n - 1) + fibonacci(n - 2), + } + } + + type FunctionPointer = fn(u32) -> u32; + + let fib : FunctionPointer = fibonacci; + println!("Fib: {}", fib(4)); + ///////////////////////// // 3. Pattern matching // ///////////////////////// -- cgit v1.2.3 From 07ffb8314f260ddabe8a7f01278f01df098c28c6 Mon Sep 17 00:00:00 2001 From: James Vaughan Date: Fri, 24 Mar 2023 23:21:11 -0700 Subject: Add fibonacci output comment --- rust.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rust.html.markdown') diff --git a/rust.html.markdown b/rust.html.markdown index 9e07e005..c677ed96 100644 --- a/rust.html.markdown +++ b/rust.html.markdown @@ -223,7 +223,7 @@ fn main() { type FunctionPointer = fn(u32) -> u32; let fib : FunctionPointer = fibonacci; - println!("Fib: {}", fib(4)); + println!("Fib: {}", fib(4)); // 5 ///////////////////////// // 3. Pattern matching // -- cgit v1.2.3 From 4635601b6a3c6d510bfdafb818051d801bbb438c Mon Sep 17 00:00:00 2001 From: KIM Taegyoon Date: Fri, 8 Sep 2023 14:32:43 +0900 Subject: added block comments (#4743) --- rust.html.markdown | 3 +++ 1 file changed, 3 insertions(+) (limited to 'rust.html.markdown') diff --git a/rust.html.markdown b/rust.html.markdown index c677ed96..526d20d5 100644 --- a/rust.html.markdown +++ b/rust.html.markdown @@ -30,6 +30,9 @@ Rust not only fast, but also easy and efficient to code in. // This is a comment. Line comments look like this... // and extend multiple lines like this. +/* Block comments + /* can be nested. */ */ + /// Documentation comments look like this and support markdown notation. /// # Examples /// -- cgit v1.2.3