You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Q16. Which example correctly uses std::collections::HashMap's Entry API to populate counts?
use std::collections::HashMap;fnmain(){letmut counts = HashMap::new();let text = "LinkedIn Learning";for c in text.chars(){// Complete this block}println!("{:?}", counts);}
for c in text.chars(){ifletSome(count) = &mut counts.get(&c){
counts.insert(c,*count + 1);}else{
counts.insert(c,1);};}
for c in text.chars(){let count = counts.entry(c).or_insert(0);*count += 1;}
for c in text.chars(){let count = counts.entry(c);*count += 1;}
for c in text.chars(){
counts.entry(c).or_insert(0).map(|x| x + 1);}
Q17. Which fragment does not incur memory allocations while writing to a "file" (represented by a Vec)?
use std::collections::HashMap;fnmain() -> Result<(),Box<dyn std::error::Error>>{letmut v = Vec::<u8>::new();let a = "LinkedIn";let b = 123;let c = '🧀';// replace this lineprintln!("{:?}", v);Ok(())}
Q27. Your application requires a single copy of some data type T to be held in memory that can be accessed by multiple threads. What is the thread-safe wrapper type?
Q60. Which types are not allowed within an enum variant's body?
zero-sized types
structs
trait objects
floating-point numbers
Q61. Which example correctly uses std::collections::HashMap's Entry API to populate counts?
use std::collections::HashMap;fnmain(){letmut counts = HashMap::new();let text = "LinkedIn Learning";for c in text.chars(){// Complete this block}println!("{:?}", counts);}
for c in text.chars(){ifletSome(count) = &mut counts.get(&c){
counts.insert(c,*count + 1);}else{
counts.insert(c,1);};}
for c in text.chars(){let count = counts.entry(c).or_insert(0);*count += 1;}
for c in text.chars(){let count = counts.entry(c);*count += 1;}
for c in text.chars(){
counts.entry(c).or_insert(0).map(|x| x + 1);}
Q62. To convert a Result to an Option, which method should you use?
.as_option()
.ok()
.to_option()
.into()
Q63. Which statement about this code is true?
fnmain(){let c = 'z';let heart_eyed_cat = '😻';}
Both are character literals.
heart_eyed_cat is an invalid expression.
c is a string literal and heart_eyed_cat is a character literal.
Both are string literals.
Q64. What is an alternative way of writing slice that produces the same result?
...let s = String::form("hello");let slice = &s[0..2];
let slice = &s[len + 2];
let slice = &s[len - 2];
let slice = &s.copy(0..2);
let slice = &s[..2];
Q65. How would you select the value 2.0 from this tuple?
let pt = Point2D(-1.0,2.0)
pt[1]
pt(1)
pt.iter().nth(1)
pt.1
Q66. What is the purpose of the move keyword in Rust?
To indicate that a value should be moved instead of copied.
To indicate that a value should be copied instead of moved.
To indicate that a value should be borrowed instead of owned.
To indicate that a value should be owned instead of borrowed.