linkedin-skill-assessments-quizzes

Rust (Programming Language)

Q1. Which type cast preserves the mathematical value in all cases?

Q2. What do the vertical bars represent here?

str::thread::spawn(|| {
    println!("LinkedIn");
});

reference

Q3. Which choice is not a scalar data type?

Q4. _ cannot be destructured.

reference

Q5. Which cargo command checks a program for error without creating a binary executable?

Q7. What is an alternative way of writing slice that produces the same result?

...
let s = String::form("hello");
let slice = &s[0..2];

Q8. Using the ? operator at the end of an expression is equivalent to _.

Q9. Which is valid syntax for defining an array of i32 values?

Q10. What syntax is required to take a mutable reference to T, when used within a function argument?

fn increment(i: T) {
    // body elided
}

Q11. The smart pointers Rc and Arc provide reference counting. What is the API for incrementing a reference count?

reference

Q12. What happens when an error occurs that is being handled by the question mark (?) operator?

Q14. In matching patterns, values are ignored with _.

Q15. Defining a _ requires a lifetime parameter.

Rust book reference

Q16. Which example correctly uses std::collections::HashMap’s Entry API to populate counts?

use std::collections::HashMap;
fn main() {
    let mut counts = HashMap::new();
    let text = "LinkedIn Learning";
    for c in text.chars() {
        // Complete this block
    }
    println!("{:?}", counts);
}
for c in text.chars() {
    if let Some(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);
}

reference

Q17. Which fragment does not incur memory allocations while writing to a “file” (represented by a Vec)?

use std::collections::HashMap;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut v = Vec::<u8>::new();

    let a = "LinkedIn";
    let b = 123;
    let c = '🧀';

    // replace this line

    println!("{:?}", v);

    Ok(())
}
write!(&mut v, "{}{}{}", a, b, c)?;
v.write(a)?;
v.write(b)?;
v.write(c)?;
v.write(a, b, c)?;
v.write_all(a.as_bytes())?;
v.write_all(&b.to_string().as_bytes())?;
c.encode_utf8(&mut v);
  1. Answered in rust user forum
  2. reference

Q18. Does the main function compile? If so, why? If not, what do you need to change?

fn main() {
    let Some(x) = some_option_value;
}

Q19. Which statement about lifetimes is false?

Q20. When used as a return type, which Rust type plays a similar role to Python’s None, JavaScript’s null, or the void type in C/C++?

Q21. To convert a Result to an Option, which method should you use?

Q22. Which statement about the Clone and Copy traits is false?

ref from stack overflow

Q23. Why does this code not compile?

fn returns_closure() -> dyn Fn(i32) -> i32 {
    |x| x + 1
}

Rust book reference

Q24. What smart pointer is used to allow multiple ownership of a value in various threads?

Rust book reference

Q25. Which types are not allowed within an enum variant’s body?

Reference

Q26. Which statement about this code is true?

fn main() {
    let c = 'z';
    let heart_eyed_cat = '😻';
}

Reference

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?

Rust book reference

Q28. Which idiom can be used to concatenate the strings a, b, c?

let a = "a".to_string();
let b = "b".to_string();
let c = "c".to_string();

Q29. In this function. what level of access is provided to the variable a?

use std::fmt::Debug;

fn report<T:Debug>(a: &T) {
    eprintln!("info: {:?}", a);
}

Q30. Which choice is not valid loop syntax?

Q31. How do you construct a value of Status that is initialized to Waiting?

enum Status {
    Waiting,
    Busy,
    Error(String),
}

Q32. Which statement about enums is false?

Q33. What does an underscore (_) indicate when used as pattern?

Q34. What is a safe operation on a std::cell:UnsafeCell<T>?

Reference

Q35. Generics are useful when you _.

Q36. How do you create a Rust project on the command-line?

Q37. Calling.clone() _.

Reference

Q38. what is one of the roles of the let keyword?

let text = String::new("LinkedIn");

Reference

Q39. How is a new enum initialized?

enum Option_i32 {
    Some(i32),
    None,
}

Reference

Q40. What are the main difference between const and static?

Reference

Q41. Which Rust data type represents a signed integer that has the same width as a pointer of the compile target’s CPU?

Reference

Q42. When are supertraits needed?

Reference

if x {
    println!("ok");
}

Reference

Q44. How do you access the married data in this struct?

struct person = Person {
    height: u64,
    weight: u64,
    married: bool
}

Reference

Q45. To mark a function as visible to other crates, what do you need to do to its definition?

Reference

Q46. Which choice is a compound data type?

Reference

Q47. How could you make this function compile?

fn main() {
    let x = 5;
    println!("The value of x is: {}", x);
    x = 6;
    println!("The value of x is: {}", x);
}

Reference

Q48. Using .unwrap() will _.

Reference

Q49. When should the panic! macro be called instead of using std::result::Result?

Reference

Q50. Which statement about arrays is true?

Reference

Q51. How would you select the value 2.0 from this tuple?

let pt = Point2D(-1.0, 2.0)

Reference

Q52. When writing tests, which macro should you use to assert equality between two values?

Reference

Q53. Which code statement in Rust is used to define a BTreeMap object?

Reference

Q54 .Rust is known to be memory safe. Which feature is the main reason for the memory safety of Rust?

Reference

Q55 . To support Dynamic Sized variables, what should we use in place of “f32”?

Reference

Q56 . What is “Drop” in Rust used for?

Reference

Q57 . In Rust, how is a macro from the above Rust code snippet used?

Reference

Q58 . Which library does Rust use for memory allocation?

Reference

Q59 . Who designed Rust from scratch in 2006?

Reference

Q60. Which types are not allowed within an enum variant’s body?

Q61. Which example correctly uses std::collections::HashMap’s Entry API to populate counts?

use std::collections::HashMap;
fn main() {
    let mut counts = HashMap::new();
    let text = "LinkedIn Learning";
    for c in text.chars() {
        // Complete this block
    }
    println!("{:?}", counts);
}
for c in text.chars() {
    if let Some(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?

Q63. Which statement about this code is true?

fn main() {
    let c = 'z';
    let heart_eyed_cat = '😻';
}

Q64. What is an alternative way of writing slice that produces the same result?

...
let s = String::form("hello");
let slice = &s[0..2];

Q65. How would you select the value 2.0 from this tuple?

let pt = Point2D(-1.0, 2.0)

Q66. What is the purpose of the move keyword in Rust?

reference Q67. What is the purpose of the 'static lifetime in Rust?

Q68. What is the purpose of the &mut reference in Rust?

Q69. What is the purpose of the Box<T> smart pointer in Rust?

Q70. What is the purpose of the Arc<T> smart pointer in Rust?

Q71. What is the purpose of the Rc<T> smart pointer in Rust?

Q72. What is the purpose of the Cell<T> and RefCell<T> types in Rust?

Q73. What is the purpose of the Drop trait in Rust?

Q74. What is the purpose of the From and Into traits in Rust?

Q75. What is the purpose of the Debug trait in Rust?

Q76. What is the purpose of the Display trait in Rust?

Q77. What is the purpose of the Error trait in Rust?

Q78. What is the purpose of the Clone trait in Rust?

Q79. What is the purpose of the Copy trait in Rust?

Q80. What is the purpose of the Deref and DerefMut traits in Rust?

Q81. What is the purpose of the Iterator trait in Rust?

Q82. What is the purpose of the Future trait in Rust?

Q83. What is the purpose of the Stream trait in Rust?

Q84. What is the purpose of the Result enum in Rust?

Q85. What is the purpose of the Option enum in Rust?

Q86. What is the purpose of the Mutex and RwLock types in Rust?

Q87. What is the purpose of the AsRef and AsMut traits in Rust?

Q88. What is the purpose of the Fn, FnMut, and FnOnce traits in Rust?

Q89. What is the purpose of the Send and Sync traits in Rust?

Q90. What is the purpose of the Default trait in Rust?

Q91. What is the purpose of the PartialEq and Eq traits in Rust?

Q92. What is the purpose of the PartialOrd and Ord traits in Rust?

Q93. What is the purpose of the Hash trait in Rust?

Q94. What is the purpose of the Borrow and BorrowMut traits in Rust?

Q95. What is the purpose of the Serialize and Deserialize traits in Rust?

Q96. What is the purpose of the Sized trait in Rust?

Q97. What is the purpose of the Decodable and Encodable traits in Rust?

Q98. What is the purpose of the From and Into traits in Rust?

Sure, here are 45 Rust quiz questions (Q112-Q156):

Q112. What is the purpose of the where clause in Rust?

Q113. What is the output of the following Rust code?

trait Animal {
    fn make_sound(&self);
}

struct Dog {
    name: String,
}

impl Animal for Dog {
    fn make_sound(&self) {
        println!("Woof!");
    }
}

fn main() {
    let dog = Dog { name: "Buddy".to_string() };
    dog.make_sound();
}

Q114. What is the purpose of the Self keyword in a Rust trait?

Q115. Which of the following is a valid way to define a generic function in Rust?

Q116. What is the purpose of the associated types feature in Rust traits?

Q117. What is the output of the following Rust code?

trait Foo {
    type Output;
    fn do_something(&self) -> Self::Output;
}

struct Bar;

impl Foo for Bar {
    type Output = i32;
    fn do_something(&self) -> Self::Output {
        42
    }
}

fn main() {
    let bar = Bar;
    let result = bar.do_something();
    println!("{}", result);
}

Q118. What is the purpose of the PhantomData struct in Rust?

Q119. What is the output of the following Rust code?

trait Printable {
    fn print(&self);
}

struct Person {
    name: String,
}

impl Printable for Person {
    fn print(&self) {
        println!("My name is {}", self.name);
    }
}

fn main() {
    let person = Person { name: "Alice".to_string() };
    person.print();
}

Q120. What is the purpose of the Clone trait in Rust?

Q121. What is the purpose of the Default trait in Rust?

Q122. What is the output of the following Rust code?

trait Animal {
    fn make_sound(&self) {
        println!("Generic animal sound");
    }
}

struct Dog {
    name: String,
}

impl Animal for Dog {
    fn make_sound(&self) {
        println!("Woof!");
    }
}

fn main() {
    let dog = Dog { name: "Buddy".to_string() };
    dog.make_sound();
}

Q123. What is the purpose of the PartialEq and Eq traits in Rust?

Q124. What is the purpose of the PartialOrd and Ord traits in Rust?

Q125. What is the purpose of the From and Into traits in Rust?

Q126. What is the purpose of the TryFrom and TryInto traits in Rust?

Q127. What is the purpose of the AsRef and AsMut traits in Rust?

Q128. What is the purpose of the Borrow and BorrowMut traits in Rust?

Q129. What is the purpose of the Deref and DerefMut traits in Rust?

Q130. What is the purpose of the Hash trait in Rust?

Q131. What is the purpose of the std::fmt::Display trait in Rust?

Q132. What is the purpose of the std::fmt::Debug trait in Rust?

Q133. What is the purpose of the Send and Sync traits in Rust?

Q134. What is the purpose of the Copy trait in Rust?

Q135. What is the purpose of the Drop trait in Rust?

Q136. What is the purpose of the std::ops module in Rust?

Q137. What is the purpose of the std::marker module in Rust?

Q138. What is the purpose of the std::cell module in Rust?

Q139. What is the purpose of the std::rc module in Rust?

Q140. What is the purpose of the std::arc module in Rust?

Q141. What is the purpose of the std::sync module in Rust?

Q142. What is the purpose of the std::future module in Rust?

Q143. What is the purpose of the std::pin module in Rust?

Q144. What is the purpose of the std::task module in Rust?

Q145. What is the purpose of the std::error module in Rust?

Q146. What is the purpose of the std::io module in Rust?

Q147. What is the purpose of the std::fs module in Rust?

Q148. What is the purpose of the std::net module in Rust?

Q149. What is the purpose of the std::process module in Rust?

Q150. What is the purpose of the std::thread module in Rust?

Q151. What is the purpose of the std::collections module in Rust?

Q152. What is the purpose of the std::env module in Rust?

Q157. What is the purpose of the ? operator in Rust?

Q158. What is the difference between Result<T, E> and Option<T>?

Q159. What is the purpose of the unwrap() method in Rust?

Q160. What is the purpose of the expect() method in Rust?

Q161. What is the purpose of the ? operator when used in a function that returns a Result<T, E>?

Q162. What is the purpose of the and_then() method in Rust?

Q163. What is the purpose of the or_else() method in Rust?

Q164. What is the purpose of the map() method in Rust?

Q165. What is the purpose of the map_err() method in Rust?

Q166. What is the purpose of the unwrap_or() method in Rust?

Q167. What is the purpose of the unwrap_or_else() method in Rust?

Q168. What is the purpose of the is_ok() and is_err() methods in Rust?

Q169. What is the purpose of the as_ref() and as_mut() methods in Rust?

Q170. What is the purpose of the get_or_insert() method in Rust?

Q171. What is the purpose of the get_or_insert_with() method in Rust?

Q172. What is the purpose of the take() method in Rust?

Q173. What is the purpose of the filter() method in Rust?

Q174. What is the purpose of the zip() method in Rust?

Q175. What is the purpose of the and() method in Rust?

Q176. What is the purpose of the or() method in Rust?

Q177. What is the purpose of the ok() method in Rust?

Q178. What is the purpose of the err() method in Rust?

Q179. What is the purpose of the is_some() and is_none() methods in Rust?

Q180. What is the purpose of the transpose() method in Rust?

Q181. What is the purpose of the flatten() method in Rust?

Here are 45 Rust quiz questions (Q202-Q246):

Q202. What is the purpose of the async keyword in Rust?

Q203. How does the await keyword work in Rust?

Q204. What is the purpose of the futures crate in Rust?

Q205. What is the difference between a Thread and a Task in Rust’s concurrency model?

Q206. How can you create a new thread in Rust?

Q207. What is the purpose of the Arc (Atomic Reference Counted) type in Rust?

Q208. What is the purpose of the Mutex type in Rust?

Q209. What is the difference between Arc<Mutex<T>> and Rc<RefCell<T>> in Rust?

Q210. What is the purpose of the Channel type in Rust’s concurrency model?

Q211. What is the difference between a Sender and a Receiver in a Rust channel?

Q212. What is the purpose of the RwLock type in Rust?

Q213. What is the purpose of the Barrier type in Rust?

Q214. What is the purpose of the Condvar type in Rust?

Q215. What is the purpose of the AtomicUsize type in Rust?

Q216. What is the purpose of the JoinHandle type in Rust?

Q217. What is the purpose of the Weak type in Rust’s concurrency model?

Q218. What is the difference between a Future and a Stream in Rust’s async/await model?

Q219. What is the purpose of the Select combinator in Rust’s async/await model?

Q220. What is the purpose of the join combinator in Rust’s async/await model?

Q221. What is the purpose of the All combinator in Rust’s async/await model?

Q222. What is the purpose of the Any combinator in Rust’s async/await model?

Q223. What is the purpose of the try_join combinator in Rust’s async/await model?

Q224. What is the purpose of the FutureExt trait in Rust’s async/await model?

Q225. What is the purpose of the StreamExt trait in Rust’s async/await model?

Q226. What is the purpose of the JoinError type in Rust’s async/await model?

Q227. What is the purpose of the AbortHandle type in Rust’s async/await model?

Q228. What is the purpose of the AbortRegistration type in Rust’s async/await model?

Q229. What is the purpose of the FutureObj type in Rust’s async/await model?

Q230. What is the purpose of the LocalKey type in Rust’s async/await model?

Q231. What is the purpose of the task_local macro in Rust’s async/await model?

Q232. What is the purpose of the block_in_place function in Rust’s async/await model?

Q233. What is the purpose of the spawn_blocking function in Rust’s async/await model?

Q234. What is the purpose of the runtime module in Rust’s async/await model?

Q235. What is the purpose of the pin module in Rust’s async/await model?

Q236. What is the purpose of the block_on function in Rust’s async/await model?

Q237. What is the purpose of the ThreadPool type in Rust’s async/await model?

Q238. What is the purpose of the JoinSet type in Rust’s async/await model?

Q239. What is the purpose of the MultiTask type in Rust’s async/await model?

Q240. What is the purpose of the `AsyncRea