Save
Busy. Please wait.
Log in with Clever
or

show password
Forgot Password?

Don't have an account?  Sign up 
Sign up using Clever
or

Username is available taken
show password


Make sure to remember your password. If you forget it there is no way for StudyStack to send you a reset link. You would need to create a new account.
Your email address is only used to allow you to reset your password. See our Privacy Policy and Terms of Service.


Already a StudyStack user? Log In

Reset Password
Enter the associated with your account, and we'll email you a link to reset your password.
focusNode
Didn't know it?
click below
 
Knew it?
click below
Don't Know
Remaining cards (0)
Know
0:00
Embed Code - If you would like this activity on your web page, copy the script below and paste it into your web page.

  Normal Size     Small Size show me how

RUST 1

QuestionAnswer
What are the roles of rustup, rustc and the cargo commands? Cargo: a packaging and build tool Rustup: toolchain management tool Rustc: just the compiler
How does rust ensure memory safety? Ownership
Where are rust variables stored as the program executes? Stack
Does the code compile? let x = 1; let mut y = 1; let x = “helllo” y= 3.14; No because setting floating point value after initially setting it to an int
What are the types of x and y? let x = 1.0; let y = 3; x is f64 y = i32
What is the problem with this function? fn add_numbers(a, b) -> i32 { a + b } No types for x and y in the parentheses of function (need :i32)
Does the code compile? let x = 1; let y = 2; let z = if x > y {x} else {y}; The code compiles
Does the following code compile? let x = 1; let y = x; println!(“{},{}”, x, y); The code compiles because i32 has a copy trait
Does the following code compile? let x = “hello”.to_string(); let y = x; println!(“{},{}”, x, y); No. Absence of copy type so ownership results in no access to x anymore
What part of memory will hold the integer value (42) after executing this code? let x = Box::new(42); Heap
What is the output of the following program? (...) fn main(){ let values = vec![1,2,3,4]; let result = sum(value); println!(“the sum of {:?} is {}”, values, result); } Problem: values stops existing after let result line
What is the output of the following program? fn main() { let values = vec![“one”.to_string(), “two”.to_string()]; let x = values[values.len()-2]; println!(“{}, x) } Doesn’t compile Dynamic data structures, tracks length at runtime so ownership can’t move data out of vector Can’t index vectors cause you don’t know the length for sure Cannot move out of index of ‘Vec<String>’
What are ownership rules? Each value in rust has an owner There can only be one owner at a time When the owner goes out of scope, the value will be dropped
What are the Borrow Rules? At given given time, you can have either one mutable reference of any number of immutable references References must always be valid
What is the data type of s in the following example? fn main () { let s = &“hello”.to_string()[1..2]; println!(“{s}”); } String slice: &str
Is this a valid struct definition? #derive(Debug, Clone, Copy)] struct person{ name: string; x = i32; } No, you can't copy a string type so Copy trait can't be implemented
Where do you need to provide an irrefutable pattern for matching? Variable assignment Parameters of function For loops
What is the data type of x let x = Some(12); Option<i32>
What does Option::<T>::upwrap() do? Panics
Change the line to make it work? fn sum(row: &str) -> Result<i32>, ParseIntError>{ let mut acc = 0; acc += token.parse::<i32>(); acc += token.parse::<i32>()?;
What is the potential danger of creating a &str slice reference, like let s = &unknown_string[4..9] If they’re unicode encoded so it may end up in the middle of character because there is variable length encoding Program would panic
String vs &str? String owns the data, str always borrows the data
What is the data type of r? let mut v = vec![1,2,3,4]; let r = &mut x[1..3]; r:&mut[i32]
What is the type and value of x? Let mut m = HashMap::new(); m.insert(“for”,”bar”); Let x = m.entry(“bar”).or_insert(“baz”); x:&mut &str ->“baz”
What’s the problem with the following generic function? fn smaller<T>(a:T, b:T)->T{ if a <= b {a} else {b} } The T data type needs to have the partial order trait, so that you can compare. fn smaller<T: PartialOrd>(a: T, b: T) -> T { if a <= b { a } else { b } }
What is wrong with the following generic type implementation block? Struct Vector<T>{ … } Impl<T> Vector<T>{ … } Trait Introspect { fn kind(&self)-> &str; } Can’t implement kind
The following code doesn’t compile fn smaller<T>(x:&T, y: &T)->(...) TICKS need to be added No lifetime specification
Created by: user-1799341
Popular Engineering sets

 

 



Voices

Use these flashcards to help memorize information. Look at the large card and try to recall what is on the other side. Then click the card to flip it. If you knew the answer, click the green Know box. Otherwise, click the red Don't know box.

When you've placed seven or more cards in the Don't know box, click "retry" to try those cards again.

If you've accidentally put the card in the wrong box, just click on the card to take it out of the box.

You can also use your keyboard to move the cards as follows:

If you are logged in to your account, this website will remember which cards you know and don't know so that they are in the same box the next time you log in.

When you need a break, try one of the other activities listed below the flashcards like Matching, Snowman, or Hungry Bug. Although it may feel like you're playing a game, your brain is still making more connections with the information to help you out.

To see how well you know the information, try the Quiz or Test activity.

Pass complete!
"Know" box contains:
Time elapsed:
Retries:
restart all cards