Rust Learning Cohort #1122
Replies: 25 comments 35 replies
-
Rust Learning Cohort Q&A ThreadAsk your VC Rust Learning Cohort questions here! ❓ Do you have a comment or suggestion? 💬 Pop it in here as well! |
Beta Was this translation helpful? Give feedback.
-
Rust Resources ThreadHey all you budding Rustaceans! If you have any Rust resources to share with the group, add them as a comment on this post! Resource CategoriesUse the categorization emojis below to help people understand more about your shared resource at a glance. You can add multiple emojis on a single resource if necessary!
ExamplesBelow is a template you can copy and adjust for your post. :emoji-code: [Resource Title](resource-url) rustlings Website 🗣️ |
Beta Was this translation helpful? Give feedback.
-
Week 1 DiscussionAnd... we're off! 🚀 Tell us:
Pop Quiz!Click on "Answer" to reveal the solution. Let us know how you did in the thread! Question 1What is the name of the command-line tool for managing the version of Rust on your machine? Answer
For example, you can write Question 2Every executable Rust program must contain a function with the name: Answer
In your program, you add a main function like this: fn main() {
// your code here
} Question 3Let's say you have the following program in a file fn main() {
println!("Hello world!");
} Say you then run the command a. Answer
Running Question 4Say you just downloaded a Cargo project, and then you run a. Cargo downloads and builds any dependencies of the project AnswerCargo watches for file changes and re-executes the binary on a change Cargo does not watch your files by default. But you can use plugins like cargo-watch for this purpose. |
Beta Was this translation helpful? Give feedback.
-
Did anybody else find it weird that the Rust complier demands that you declare the type of a |
Beta Was this translation helpful? Give feedback.
-
Week 2 Discussion
Pop Quiz!Click on "Answer" to reveal the solution. Let us know how you did in the thread! NOTE: Questions 1-9 cover chapter 3 and questions 10-30 cover chapter 4, so you tortoises might want to come back to these later! 🐢 Question 1Which statement best describes what it means if a variable a. You cannot create a reference to Answerb. Immutable means "not mutable", or not changeable. Question 2What is the keyword used after Answer
For example, you can make a mutable variable Question 3Which of the following statements is correct about the difference between using a. The compiler will error if a Answerd. Question 4The largest number representable by the type a. 2127 - 1 Answera. 2127 - 1 In general, a signed number with n bits can represent numbers between -(2n - 1) and 2n - 1 - 1. Question 5If a. It will always panic. Answerc. It depends on the compiler mode. This expression will panic in debug mode and return 255 in release mode. Question 6The keyword for declaring a new function in Rust is: Answer
Question 7In Rust, a curly-brace block like
a. 1 only Answerd. 1 and 3 A block is an expression (1) that is allowed to contain statements. It also defines a syntactic scope for let-bindings inside it (3). Question 8True or False: Executing these two pieces of code results in the same value for Snippet 1: let x = if cond { 1 } else { 2 }; Snippet 2: let x;
if cond {
x = 1;
} else {
x = 2;
} (Note: both of these snippets compile!) AnswerTrue The first if-expression is a more concise way of representing the behavior of the second if-statement. Note that Rust does not require Question 9True or False: This code will terminate (that is, it will not loop forever). fn main() {
let mut x = 0;
'a: loop {
x += 1;
'b: loop {
if x > 10 {
continue 'a;
} else {
break 'b;
}
}
break;
}
} AnswerTrue It will in fact terminate after the first iteration of the loop. Question 10Which of the following best describes the difference between the stack and the heap? a. The stack can hold pointers to data stored on the heap, while the heap only holds data without pointers. Answerb. The stack holds data associated with a specific function, while the heap holds data that can outlive a function. Frames in the stack are associated with a specific function, and are deallocated when the function returns. Data on the heap can live indefinitely. Note that both stack and heap data can be mutable and can be copyable. The heap is allowed to contain pointers (even to the stack, as we will see later). Question 11Consider the execution of the following snippet, with the final state shown: #fn main() {
let a = Box::new(15);
let b = a;
let c = Box::new(15);`[]`
#} In the final state, how many copies of the number Answer2 The two boxes contain the two copies of the number 15. The assignment Question 12Which of the following is NOT a kind of undefined behavior? a. Having a pointer to freed memory in a stack frame Answera. Having a pointer to freed memory in a stack frame It can be perfectly safe to have a pointer to freed memory in a stack frame. The important thing is to not use that pointer again, e.g. by reading it or freeing it. Question 13Say we have a function that moves a box, like this: fn move_a_box(b: Box<i32>) {
// This space intentionally left blank
} Below are four snippets which are rejected by the Rust compiler. Imagine that Rust instead allowed these snippets to compile and run. Select each snippet that would cause undefined behavior, or select "None of these snippets" if none of these snippets would cause undefined behavior. Snippet 1: let b = Box::new(0);
let b2 = b;
move_a_box(b); Snippet 2: let b = Box::new(0);
move_a_box(b);
println!("{}", b); Snippet 3: let b = Box::new(0);
let b2 = b;
println!("{}", b);
move_a_box(b2); Snippet 4: let b = Box::new(0);
move_a_box(b);
let b2 = b; None of these snippets AnswerSnippets 1, 2, and 4 The key idea is that when a box is passed to
However, doing Question 14Consider the following program, showing the state of memory after the last line: #fn main() {
let x = Box::new(0);
let y = Box::new(&x);`[]`
#} If you wanted to copy out the number Answer3
Question 15Consider the following program, showing the state of memory after the last line: fn get_first(vr: &Vec<i32>) -> i32 {
vr[0]
}
fn main() {
let mut v = vec![0, 1, 2];
let n = get_first(&v);
println!("{} {}", n, v[1]);`[]`
} Which of the following best explains why a. Answerb. References are non-owning pointers. Therefore passing Question 16Consider the permissions in the following program: #fn main() {
let mut s = String::from("Hello");
let t = &mut s;
/* here */
t.push_str(" world");
println!("{}", s);
#} At the point marked a. R Answerd. No permissions The mutable borrow Question 17Consider the permissions in the following program: fn get_first(v: &Vec<String>) -> &str {
&v[0]
}
fn main() {
let mut strs = vec![
String::from("A"), String::from("B")
];
let first = get_first(&strs);
if first.len() > 0 {
strs.push(String::from("C"));
}
} Which of the following best explains why a. Because Answerb. When Question 18Consider this unsafe program: #fn main() {
let v1 = vec![1, 2, 3];
let mut v2 = v1;
v2.push(4);
println!("{}", v1[0]);`[]`
#} Which of the following best describes the point at which undefined behavior occurs in this program? a. Answerd. The undefined behavior arises because Question 19Which of the following is NOT a valid kind of fix to the issue of returning a stack reference from a function? a. Use a reference-counted pointer Answerb. Extend the lifetime of the stack frame A stack frame cannot have its lifetime extended, so that is not a valid solution. Question 20Which of the following best explains why an a. A Answerb. A If a Question 21The following code snippet does not compile: let s = String::from("Hello world");
let s_ref = &s;
let s2 = *s_ref;
println!("{s2}"); Which of the following best describes the undefined behavior that could occur if this program were allowed to execute? a. The string is freed twice at the end of the program Answera. The string is freed twice at the end of the program The Question 22The following program does not compile: fn copy_to_prev(v: &mut Vec<i32>, i: usize) {
let n = &mut v[i];
*n = v[i - 1];
}
fn main() {
let mut v = vec![1, 2, 3];
copy_to_prev(&mut v, 1);
} Which of the following best describes the undefined behavior that could occur if this program were allowed to execute? a. The read of Answerd. There is no undefined behavior in this program This program is safe. No undefined behavior could occur if it were executed. (If The issue is that Rust doesn't know for sure that Question 23Consider the variables fn main() {
let s = String::from("hello");
let s2: &String = &s;
let s3: &str = &s[..];
} a. Answera. The type fn main() {
println!(
"&String={} &str={}",
std::mem::size_of::<&String>(),
std::mem::size_of::<&str>(),
);
} Also, note that Rust will implicitly convert string references to either Question 24Say you are writing a function with the following spec:
Which of the following is the most appropriate type signature for a function implementing this spec? Snippet 1: fn round_all(v: Vec<f32>); Snippet 2: fn round_all(v: &Vec<f32>); Snippet 3: fn round_all(v: &mut Vec<f32>); Snippet 4: fn round_all(v: &Vec<f32>) -> Vec<f32>; AnswerSnippet 3 The spec calls for the input to be mutated in-place, therefore the most appropriate type signature accepts a mutable reference to the input. An immutable reference or an owned vector are both inappropriate for this spec. Question 25Say you are writing a function with the following spec:
Which of the following is the most appropriate type signature for a function implementing this spec? Snippet 1: fn find_contains(haystack: &[String], needle: &str) -> Vec<String>; Snippet 2: fn find_contains(haystack: &[String], needle: &str) -> Vec<&String>; Snippet 3: fn find_contains(haystack: &Vec<String>, needle: String) -> Vec<String>; Snippet 4: fn find_contains(haystack: &Vec<String>, needle: &str) -> &[String]; AnswerSnippet 2 For Question 26Rust normally disallows multiple mutable accesses to the same array, even when those accesses are disjoint. For example, this function does not compile: fn main() {
let mut v = vec![0, 1, 2, 3];
let (r0, r1) = (&mut v[0..2], &mut v[2..4]);
r0[0] += 1;
r1[0] += 1;
} However, the Rust standard library has a function fn main() {
let mut v = vec![0, 1, 2, 3];
let (r0, r1) = v.split_at_mut(2);
r0[0] += 1;
r1[0] += 1;
} Which of the following best describes how it's possible to implement a. Answera. As discussed in Chapter 4.3 "Fixing a Safe Program: Mutating Different Array Elements", functions like Question 27Consider the permissions in the following program: #fn main() {
let s = String::new();
let s_ref = &s;`(focus,paths:*s_ref)`
#println!("{s_ref}");
#} Which of the following best explains why a. Ownership permits mutation, and mutating Answerc. Ownership permits moving, and moving out of a reference can cause a double-free The Question 28Consider the set of Rust programs that contain no a. The borrow checker always accepts programs without undefined behavior Answerc. The borrow checker always rejects programs with undefined behavior, and The borrow checker always rejects programs with undefined behavior, but may sometimes reject programs without undefined behavior (i.e., are perfectly safe). In technical terms, the borrow checker is a sound and incomplete analysis. Question 29The function fn extract(b: &Box<i32>) -> i32 {
let b2: Box<i32> = *b;
*b2
} Imagine that the borrow checker did not reject this function. Determine whether there exists an input such that the function would cause undefined behavior if executed on that input. AnswerThis function COULD cause undefined behavior This function would cause a double-free on any input. Question 30The function fn get_first(strs: &mut (String, String)) -> &mut String {
&mut strs.0
}
fn get_second(strs: &mut (String, String)) -> &mut String {
&mut strs.1
}
fn transfer_string(strs: &mut (String, String)) {
let fst = get_first(strs);
let snd = get_second(strs);
fst.push_str(snd);
snd.clear();
} Imagine that the borrow checker did not reject this function. Determine whether there exists an input such that the function would cause undefined behavior if executed on that input. AnswerThis function could NOT cause undefined behavior The borrow checker rejects this function because it assumes that |
Beta Was this translation helpful? Give feedback.
-
I read a couple of blogs today on using Rust with AWS Lambda that I thought they were really insightful. |
Beta Was this translation helpful? Give feedback.
-
Week 3 DiscussionWe're getting deeper into rust - how are you feeling about the language? What is exciting and what is confusing? 🦀 Pop QuizHey, you tortoises! 🐢 Go back to last week's pop quiz and try questions 1-9. For all you hares 🐇 out there, questions 1-4 cover chapter 5 and questions 5-9 cover chapter 6. Remember to let us know how you did! Question 1Which statement best describes a difference between the a. Answera. Question 2What is the keyword for constructor functions in Rust? a. Answerd. None of the above Rust does not have a keyword for constructor functions. The idiomatic way to define a constructor function is to make an associated function called Question 3Say you have a variable impl Vec<i32> {
fn len(&self) -> usize {
/* ... */
}
} If you try to compile the expression a. It compiles, because the Answera. It compiles, because the The expression Question 4Consider these two methods that increment a field of a struct. Which style would be more idiomatic for Rust? struct Point(i32, i32);
impl Point {
fn incr_v1(mut self) { self.0 += 1; }
fn incr_v2(&mut self) { self.0 += 1; }
} a. Answerb. The Question 5Consider these two representations of a struct Result1<T, E> {
ok: Option<T>,
err: Option<E>,
}
enum Result2<T, E> {
Ok(T),
Err(E)
} The enum a. The struct uses more space in memory at runtime than the enum Answerc. The struct contains It's perfectly fine to have structs contain Question 6Consider this method implemented for the impl<T> Option<T> {
fn unwrap_or(self, other: T) -> T {
match self {
Some(t) => t,
None => other
}
}
} Which sentence best describes the behavior of this function? a. Returns the object inside Answera. Returns the object inside This function "unwraps" the option by consuming ownership of it and retrieving the value inside, but if no value exists then it falls back by returning Question 7Consider these two implementations of a function to decrement an unsigned number twice. fn decr_twice_v1(n: u32) -> Option<u32> {
match n {
0 => None,
1 => None,
n2 => Some(n2 - 2)
}
}
fn decr_twice_v2(n: u32) -> Option<u32> {
if n == 0 {
None
} else if n == 1 {
None
} else {
Some(n - 2)
}
} The functions have the same behavior for: a. No inputs Answerc. All inputs The Question 8Which control flow construct would be most idiomatic to use in the following function? enum Location {
Point(i32),
Range(i32, i32)
}
fn print_range_max(loc: &Location) {
// print the second field of Range, if loc is a Range
} a. Answera. If the function only has an effect in one condition, an Question 9Which control flow construct would be most idiomatic to use in the following function? enum Location {
Point(i32),
Range(i32, i32)
}
fn get_start(loc: &Location) -> i32 {
// return the first field of Range or the only field of Point
} a. Answerb. If the function needs to return a value for each condition, then a |
Beta Was this translation helpful? Give feedback.
-
Week 4 DiscussionOnward and upward with rust! We're into our 4th week of Rust 🐇
Pop QuizHappy March fellow learners! 🐢 Tortoises, check out questions 10-30 of Week 2's discussion post for chapter 4 quiz questions. Questions 1-4 from last week's discussion post cover chapter 5. 🐇 All you hares getting ready for spring, questions 1-7 cover chapter 7 and questions 8-12 cover chapter 8. Tell us how you did! Were there any answers that surprised you? Question 1Which is the correct order, where "A > B" means "A contains B"? a. crate > package > module Answerc. package > crate > module A package is the top-level organizational unit, containing crates. A crate contains modules. Question 2Imagine you see a Rust package
How many crates does this package contain? Write your answer as a digit, e.g. 0, 1, and so on. Answer3
Question 3Which of the following is NOT a benefit of using modules? a. Modules encapsulate implementation details that shouldn't be used by external clients Answerb. Modules boost the runtime performance of interdependent code within the same module Modules have no effect on runtime, they are purely for compile-time organization. Question 4What is the keyword you use at the start of an absolute path to an item in the current crate? Answer
For example, an absolute path to item Question 5Which of the following statements best describes the function of the a. Answerd.
Question 6Consider this module and pub mod parent {
pub fn a() {}
fn b() {}
pub mod child {
pub fn c() {}
}
}
fn main() {
use parent::{*, child as alias};
// ...
} Inside Answer5 There are two paths to Question 7Imagine a Rust package with the following directory structure:
The contents of each file are: // engine/analysis.rs
pub fn run() {} // engine.rs
mod analysis;
pub use analysis::*; // lib.rs
pub mod engine; Say that another Rust developer is using the Answer
The module tree generated by this directory structure is as follows:
Therefore the path to Question 8Which call to this fn find_until(v: &Vec<i32>, n: i32, til: usize) -> Option<usize> {
for i in 0 .. til {
if v[i] == n {
return Some(i);
}
}
return None;
} a. Answerd. If Question 9What is the difference between using a. Answerb.
Question 10What is the maximum number of times a heap allocation could occur in this program? Write your answer in digits, e.g. 0 or 1. let s1 = String::from("tic");
let s2 = String::from("tac");
let s3 = String::from("toe");
let s = s1 + "-" + &s2 + "-" + &s3; Answer7 One allocation for each call to Question 11Which statement is the best explanation for why Rust does not allow string indexing? a. Indexing strings is inefficient because string are null-terminated so their length cannot be efficiently computed Answerc. Indexing strings is ambiguous because strings represent several granularities of sequenced data A UTF-8 string can be interpreted as a sequence of bytes, characters, or grapheme clusters. None of these is necessarily the "default" way of interpreting a string, so a default indexing operation does not make sense. Question 12Which statement best describes the difference between the types of a string slice a. Answera.
|
Beta Was this translation helpful? Give feedback.
-
Week 5 DiscussionLet's go! We're into our 5th week of Rust 🐇
Pop Quiz🐢 Tortoises, check out questions 5-9 of Week 3's discussion post for chapter 6 quiz questions. Questions 1-7 from last week's discussion post cover chapter 7. 🐇 All you hares getting ready for spring, questions 1-4 cover chapter 9, questions 5-9 cover chapter 10, and questions 10-13 cover chapter 11. How did you score? Question 1What is the name of the environment variable you should set to Answer
For example, you can run from the command line: Question 2Which of the following is NOT a good reason to use a panic? a. The program should stop executing as soon as possible Answerd. The program has reached an error state which should be communicated to a caller function A panic should not be used to communicate failure within the program. The default assumption is that caller functions will not try to catch panics. Question 3Which of these statements best describes why a. Because Answerb. Because
Question 4A Rust programmer is designing a library for writing command-line interfaces. fn parse_flag_v1(flag: &str) -> Result<String, String> {
match flag.strip_prefix("--") {
Some(no_dash) => Ok(no_dash.to_string()),
None => Err(format!("Invalid flag {flag}"))
}
}
fn parse_flag_v2(flag: &str) -> String {
match flag.strip_prefix("--") {
Some(no_dash) => no_dash.to_string(),
None => panic!("Invalid flag {flag}")
}
} a. Answera. Here, the programmer would likely want to use a recoverable error (the Question 5Imagine using a third-party function whose implementation you don't know, but whose type signature is this: fn mystery<T>(x: T) -> T {
// ????
} Then you call let y = mystery(3); Assuming Answer3 The only possible function (without unsafe code) that has the signature fn mystery<T>(x: T) -> T {
x
} The function could of course panic or print, but the return value can only be the input. Question 6The following are statements about what kinds of trait implementations are permitted by Rust. Select each statement which is true. a. You can implement an external trait for a local type Answerb. You can implement an external trait for an external type The "orphan rule" requires that you cannot implement an external trait for an external type, to ensure code doesn't break if two crates provide conflicting implementations. Question 7What is the smallest set of trait bounds on fn f<T: /* ??? */>(t: &T) {
let t2 = t.clone();
println!("{t2}");
} a. Answerb. Because Question 8Which kind of programming error is a lifetime supposed to prevent? a. Indexing past the bounds of an array (buffer overflow) Answerc. Using a reference to an object after its memory has been freed Lifetimes help identify how long an object is "live", and whether references to that object outlive the object itself. Question 9If a reference has a lifetime a. The data under the reference is never deallocated Answera. The data under the reference is never deallocated
Question 10What is the annotation you add to a function to indicate that it's a unit test? Answer
This informs the cargo testing harness to treat the function as a test and not library code. Question 11When running a. Reading data from a single database Answerd. Writing text to a single file Tests are run in parallel by default, so actions which are not thread-safe (like writing to a single file) may cause a race condition. Question 12Consider a program with the following unit test: #[test]
fn test_the_logger() { /* ... */ }
#[test]
fn test_the_database() { /* ... */ }
#[test]
fn test_logger_and_database() { /* ... */ } What is the shortest string you can pass to Answer
The shortest substring string that is not contained in Question 13Which of the following is NOT a good reason to wrap unit tests in a. It gives your tests access to private functions Answera. It gives your tests access to private functions All unit tests in a given file have access to that file's private functions, regardless of being in a |
Beta Was this translation helpful? Give feedback.
-
Week 6ish - Break time!We hope you're enjoying a change of seasons (perhaps 🌸 🌷 s or maybe 🍂 ) this March. What does this mean for you?
What would you like to see next?
|
Beta Was this translation helpful? Give feedback.
-
Week 6How was your spring break? Did everyone have some time to dig their claws in? 🦀 We're Back to the Races!!Let us know where you are in the curriculum! We've created a suggested schedule, but you can approach the learning journey I whichever way works best for you! We'll be posting a poll in the #learning-together Slack channel this week about when to meet for our first group discussion. 💬 Until then, comment on this post to share your discoveries from over the break! 💡 Did you come across anything cool? Did something you learn remind you of another programming language? Is there a concept you still don't quite understand that you'd like to talk about? Share it all here in the comments! 🧠 Lastly, don't hesitate to reach out to your fearless leaders – @wheeleruniverse, @virtualandy, and @meg-gutshall – with any questions, comments, or suggestions. It's go time, baby! 🚀 |
Beta Was this translation helpful? Give feedback.
-
Week 7Did you know it's National Grilled Cheese Day? I know I'm taking the celebrations very seriously! 🍞🧀 🔥 ScheduleHare TrackTortoiseI would encourage Tortoise folks to reach out for any help. The lifetimes in Rust are no joke. 🤔 💭 ProjectsThe Guessing Game, CLI, and Web Server have all been very interesting. The "book" makes it too easy in my opinion. I would like to see how you expand these projects from the walkthrough the book provides. For example, I challenged myself to handle CTRL+C in my Web Server implementation. Being familiar with Web Servers it was crucial functionality I am too used to by now. It's proven difficult, yet rewarding. 🥇 I wonder who can make the most enjoyable Guessing Game? There could be a prize in store... 🤫 If you're bored with those projects already @virtualandy and I have been working on some new ideas to bring to the cohort. Stay tuned! Maybe you can comment on this post if you have any ideas you have thought about? Is anyone interested in game development? LeetCode problems could be fun. 😏 Lastly, remember that you're NOT alone and that you CAN do this! 💞 |
Beta Was this translation helpful? Give feedback.
-
Regarding the absolute ocean of available crates, here are various approaches to finding something useful: I found this: blessed.rs. It's less like google for crates (crates.io) and more like the old-school yahoo homepage for crates. There's also lib.rs which organizes crates by download popularity. |
Beta Was this translation helpful? Give feedback.
-
I found this YT video really helpful as it walks through all the conversions that you can do with Results and Options for error handling: Rust's Most Important Containers 📦 10 Useful Patterns |
Beta Was this translation helpful? Give feedback.
-
If you're using VSCode as your Rust editor, this setting for Inlay Hints is marvelous: |
Beta Was this translation helpful? Give feedback.
-
Week 8Sorry for the late post! I have been busy listening to Taylor Swift's latest album The Tortured Poets Department that came out today. ✨ ScheduleHare TrackTortoise TrackProjectsPlease please please share how your projects are going. We can help too if you need it. I am looking into building a Platformer game in Rust. How exciting is that? 🤔 SwagWho wants Rust Learning Cohort © swag? We're working on something tangible we can cling to when this is all over. Actually if you have any cool designs we would love to hear about them. You may even win a prize if we love it. 😍 |
Beta Was this translation helpful? Give feedback.
-
Week 9 🕘
📰 Let's look good and feel good about learning Rust!We need help designing Rust learning cohort related swag. 👕 🎩 🧦
( A quick mock example of what Rust swag could look like...please send us ideas! ) |
Beta Was this translation helpful? Give feedback.
-
Week 10 🔟 🦀
Live Sync Up 🎤We're still planning on a live Zoom/Twitch to get a group of us talking about Rust together. Post potential dates here or in Slack and we'll figure it out. Rust Swag 👕Send ideas if you have any! We're still on the hunt for what to put on a hat or shirt. If we don't get any submissions that's all good, we'll keep it real simple:
😄 |
Beta Was this translation helpful? Give feedback.
-
So, the VC cohort docs pointed at this: Watch Learn Rust with Rustlings
5.2.1 – Intro <https://www.youtube.com/watch?v=G3Vr-yswlaU&t=0s>
I did all the rustlings stuff with the 5.2.1 version.
enums3.rs changed between the 5.2.1 version and current (5.6.1).
It's possible the egghead.io walkthrough of enums3
<https://egghead.io/lessons/rust-rustlings-enums3-working-with-enums-by-pattern-matching-variants>
you're watching is mismatched with the rustlings version you expect.
On 5.2.1, I did this:
enum Message {
Move(Point),
Echo(String),
ChangeColor((u8, u8, u8)),
Quit,
}
Which matches its corresponding test:
state.process(Message::ChangeColor((255, 0, 255)));
state.process(Message::Echo(String::from("hello world")));
state.process(Message::Move(Point { x: 10, y: 15 }));
state.process(Message::Quit);
It has changed to this in 5.6.1 to remove the tuple for ChangeColor:
state.process(Message::ChangeColor(255, 0, 255));
state.process(Message::Echo(String::from("Hello world!")));
state.process(Message::Move(Point { x: 10, y: 15 }));
state.process(Message::Quit);
Which would indicate that the enum has to be this:
enum Message {
ChangeColor(u8, u8, u8), // No tuple here anymore.
Echo(String),
Move(Point),
Quit,
}
I don't see a difference with your Message::Move question about the Point
struct.
…-Nick
On Fri, May 3, 2024 at 11:00 AM Andy ***@***.***> wrote:
*Spoiler alert*
Anyone else do this in enums3.rs for rustlings?
enum Message {
ChangeColor(u8, u8, u8),
Echo(String),
Move(Point), // using Point here vs { x: u8, y: u8 }
Quit,}
That led to a little bit of a difference with what I found online and on egghead.io
walkthrough of enums3
<https://egghead.io/lessons/rust-rustlings-enums3-working-with-enums-by-pattern-matching-variants>
—
Reply to this email directly, view it on GitHub
<#1122 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAD3MRFOGPQQLQZ4XE4AJTZAPGDXAVCNFSM6AAAAABCPSFLXCVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TGMBYGQYTC>
.
You are receiving this because you were mentioned.Message ID:
<Virtual-Coffee/virtualcoffee.io/repo-discussions/1122/comments/9308411@
github.com>
|
Beta Was this translation helpful? Give feedback.
-
So, I was playing around with embedded rust and discovered that gdb does not work on Apple Silicon systems. That's a bummer. Here's a maybe workaround to use LLDB instead: https://nagaraj-fama.medium.com/m1-chip-rust-debugging-vs-code-4db332d7d6d. This seems to swing the IDE vs. VSCode discussion towards VSCode now, at least for embedded stuff. |
Beta Was this translation helpful? Give feedback.
-
Week 11I have been busy tidying up today for National Clean Up Your Room Day. 👕 🧦 🧹 ScheduleHare Track
Tortoise TrackProjectsDo you need help with any projects? Let us know! Coding is funner together. 👀 Personally I am still working on getting the Rust game engine Fyrox working. I really hope I can share something amazing with you all so soon. |
Beta Was this translation helpful? Give feedback.
-
I was setting up a new Linux instance on VMWare Fusion on top of an Apple Silicon mac and discovered that ARM64 1Password isn't a done thing yet. However, I did find that there is a beta (1Pass Betas), and when I launched it, I noticed that the terminal was filled with "tokio"! Then I found this: 1Pass Linux uses Rust. Everything is Rusting! |
Beta Was this translation helpful? Give feedback.
-
Week 12 & 13 📈Double the weeks, double the fun. Since yours truly was late to post and there's a few holidays coming and going ( Canada - Victoria Day on May 20th & US - Memorial Day on May 27th ) let's plan to study this week and next and regroup some time after that.
Hare Track 🐰💥 Congratulations! You are done schedule wise. 🏁 If you'd like to share a technical project with us, consider a PR in the main repo. Or feel free to add/edit that list of resources, topics, etc. Tortoise Track 🐢
19. Advanced Features Live Sync Up 🎤Targeting mid-late June at this point. We'll share more as soon as we know more! Rust Swag 👕Send ideas if you have any! There will be swag...we just need to dial it in. 🦀 |
Beta Was this translation helpful? Give feedback.
-
Rust Learning Wrap Up 🏆 And Special Guest Announcement! 🔈Big Announcement: The Rust Programming Language author Carol Nichols will join us on Tuesday, June 25th at 12PM ET for a live Zoom to talk all things Rust! 🦀 She’s graciously made herself available and will answer questions and educate us on Rust. We’re grateful and excited to chat with an expert! Live Sync Up 🎤Tuesday, June 25th at 12PM ET! Zoom details TBD via Slack. Preview: Check out Carol's visit on the Hanselminutes podcast where she talks about Rust's future. Hare Track 🐰
Tortoise Track 🐢
Next Steps and Wrap Up
|
Beta Was this translation helpful? Give feedback.
-
@carols10cents had some questions for us VirtualCoffee Rust learners during her visit. Answer here or in Slack and we'll make sure she sees them!
|
Beta Was this translation helpful? Give feedback.
-
Hey everyone! Welcome to Virtual Coffee's Rust Learning Cohort.
What is it? A learning cohort - follow a loose Rust learning curriculum with your friends here in VC. Learn Rust. Share knowledge. Help others.
Where? We’ll be posting reminders in the #learning-together Slack channel.
When? Starting next week! It’s okay if you can’t start just then, folks can catch up over time. Come as you are!
Questions? Ask in #learning-together or comment on the designated question thread below.
Introduction
The following is an overview of Virtual Coffee's asynchronous Rust learning cohort. It helps to already be familiar with programming and software development before you start (i.e. Rust may not be the best first programming language to learn).
The Repository
All the info you see here has also been packed into a neat little repository called the VC Rust Learning Cohort. It's available for you to fork to your heart's content!
Learning Materials
Our learning materials for this cohort are as follows... (Click the heading to reveal materials nested underneath)
Primary Resources
Rustlings
Website | GitHub
Attributions: This file lists the people that have contributed to the
rustlings
projectrustlings
is a project containing small exercises to get you used to reading and writing Rust code. This includes reading and responding to compiler messages!The Rust Programming Language
Website | GitHub
Attributions: Steve Klabnik and Carol Nichols, with contributions from the Rust Community
The most comprehensive resource for learning Rust, but a bit theoretical sometimes. You will be using this along with Rustlings!
Also, check out the Rust Book experiment!
Learn Rust with Rustlings 5.2.1
Video
Attributions: Chris Biscardi
The creator of the video suggests two methods of approach to using this resource:
Secondary Resources
Rust By Example
Website | GitHub
Learn Rust by solving little exercises! It's almost like rustlings, but online.
Schedule
This is a suggested schedule. Feel free to make a copy of this schedule and adjust to your own needs. For you, one chapter may take 1-2 hours or 1-2 weeks. Take your time!
We will be posting weekly check-ins on the #learning-together Slack channel and schedule at least two group review sessions.
High Level Overview
Suggested Schedule
🐢 Tortoise Track ➞ Plan to commit 1-2 hours per week
🐇 Hare Track ➞ Plan to commit 2-4 hours per week
Curriculum
Introduction
Reading
Video
1. Getting Started
Reading
Code
rustlings
or can use the web version)Video
2. Programming a Guessing Game
Reading
Code
This is a tutorial style chapter in the book. Code along with the instructions as well as your VC learning buddies!
3. Common Programming Concepts
Reading
Code
primitive_types4.rs
, which will be covered in 4.3Video
4. Understanding Ownership
Reading
Code
Video
5. Using Structs to Structure Related Data
Reading
Code
Video
6. Enums and Pattern Matching
Reading
Code
enums1.rs
only – the others will be covered in 18.3Video
7. Managing Growing Projects with Packages, Crates, and Modules
Reading
Code
Video
8. Common Collections
Reading
Code
Video
9. Error Handling
Reading
Code
Video
10. Generic Types, Traits, and Lifetimes
Reading
Code
Video
11. Writing Automated Tests
Reading
Code
Video
12. An I/O Project: Building A Command Line Program
Reading
Code
You can create a command-line program using the book as a guide, or try building a CLI of your own!
13. Functional Language Features: Iterators and Closures
Reading
Code
Video
14. More about Cargo and Crates.io
Reading
15. Smart Pointers
Reading
Code
Video
16. Fearless Concurrency
Reading
Code
Video
17. Object Oriented Programming Features of Rust
Reading
18. Patterns and Matching
Reading
Code
Video
19. Advanced Features
Reading
Code
Video
20. Final Project: Building a Multithreaded Web Server
Reading
Code
You can build the project suggested in the book, or create something completely yours!
21. Appendix
Reading
Code
Video
Type Conversions
Code
Video
Conclusion
Video
Beta Was this translation helpful? Give feedback.
All reactions