1.
i64 as i32
2.
usize as u64
3.
i32 as i64
4.
f64 as f32
Q 1 / 32
rust str::thread::spawn(|| { println!("LinkedIn"); });
1.
a closure
2.
a thread
3.
a future
4.
a block
Q 2 / 32
1.
integer
2.
float
3.
boolean
4.
tuple
Q 3 / 32
1.
Traits
2.
Tuples
3.
Enums
4.
Structs
Q 4 / 32
1.
cargo --version
2.
cargo init
3.
cargo build
4.
cargo check
Q 5 / 32
1.
It's creating a pointer on the heap that points to a value on the stack.
2.
It's creating a pointer on the stack that points to a value on the heap.
3.
It's creating a memory guard around values to prevent illegal access.
4.
It's an abstraction that refers to ownership. "Boxed" values are clearly labelled.
Q 6 / 32
rust ... let s = String::form("hello"); let slice = &s[0..2];
1.
let slice = &s[len + 2];
2.
let slice = &s[len - 2];
3.
let slice = &s.copy(0..2);
4.
let slice = &s[..2];
Q 7 / 32
1.
a match pattern that branches into True or False
2.
calling ok_error()
3.
calling panic!()
4.
a match pattern that may result an early return
Q 8 / 32
1.
Array<i32>::with_capacity(10)
2.
[i32]
3.
Array<i32>::new(10)
4.
[i32; 10]
Q 9 / 32
rust fn increment(i: T) { // body elided }
1.
*mut T
2.
mut ref T
3.
mut &T
4.
&mut T
Q 10 / 32
1.
.add()
2.
.incr()
3.
.clone()
4.
.increment()
Q 11 / 32
1.
The error is reported and execution continues.
2.
An exception is raised. The effect(s) of the exception are defined by the error! macro.
3.
The program panics immediately.
4.
Rust attempts to convert the error to the local function's error type and return it as Result::Err. If that fails, the program panics.
Q 12 / 32
1.
`/*`
2.
`#`
3.
`//!`
4.
`//`
Q 13 / 32
1.
`.ignore()`
2.
`an underscore (_)`
3.
..
4.
skip
Q 14 / 32
1.
function that ends the lifetime of one of its arguments
2.
struct that contains a reference to a value
3.
function with a generic argument
4.
struct that contains a reference to a boxed value
Q 15 / 32
rust 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); } rust for c in text.chars() { if let Some(count) = &mut counts.get(&c) { counts.insert(c, *count + 1); } else { counts.insert(c, 1); }; } rust for c in text.chars() { let count = counts.entry(c).or_insert(0); *count += 1; } rust for c in text.chars() { let count = counts.entry(c); *count += 1; } rust for c in text.chars() { counts.entry(c).or_insert(0).map(|x| x + 1); }
1.
rust
for c in text.chars() {
if let Some(count) = &mut counts.get(&c) {
counts.insert(c, *count + 1);
} else {
counts.insert(c, 1);
};
}
2.
rust
for c in text.chars() {
let count = counts.entry(c).or_insert(0);
*count += 1;
}
3.
rust
for c in text.chars() {
let count = counts.entry(c);
*count += 1;
}
4.
rust
for c in text.chars() {
counts.entry(c).or_insert(0).map(|x| x + 1);
}
Q 16 / 32
rust 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(()) } rust write!(&mut v, "{}{}{}", a, b, c)?; rust v.write(a)?; v.write(b)?; v.write(c)?; rust v.write(a, b, c)?; rust 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](https://users.rust-lang.org/t/formatting-and-writing-to-a-file-without-malloc-or-locks/52295/9) 2. [reference](https://doc.rust-lang.org/std/macro.write.html)
1.
rust
write!(&mut v, "{}{}{}", a, b, c)?;
2.
rust
v.write(a)?;
v.write(b)?;
v.write(c)?;
3.
rust
v.write(a, b, c)?;
4.
rust
v.write_all(a.as_bytes())?;
v.write_all(&b.to_string().as_bytes())?;
c.encode_utf8(&mut v);
Q 17 / 32
rust fn main() { let Some(x) = some_option_value; }
1.
The code does not compile. `let` statements require a refutable pattern. Add `if` before `let`.
2.
The code compiles. `let` statements sometimes require a refutable pattern.
3.
The code does not compile. `let` statements requires an irrefutable pattern. Add `if` before `let`.
4.
The code compiles. `let` do not require a refutable pattern.
Q 18 / 32
1.
Lifetimes were redundantly specified in previous version of Rust.
2.
Lifetimes are specified when a struct is holding a reference to a value.
3.
Lifetimes are specified when certain values must outlive others.
4.
Lifetimes are always inferred by the compiler.
Q 19 / 32
1.
`!`
2.
`None`
3.
`Null`
4.
`()`
Q 20 / 32
1.
`.as_option()`
2.
`.ok()`
3.
`.to_option()`
4.
`.into()`
Q 21 / 32
1.
`Copy` is enabled for primitive, built-in types.
2.
Without `Copy`, Rust applies move semantics to a type's access.
3.
When using `Clone`, copying data is explicit.
4.
Until a type implements either `Copy` or `Clone`, its internal data cannot be copied.
Q 22 / 32
rust fn returns_closure() -> dyn Fn(i32) -> i32 { |x| x + 1 }
1.
The returned `fn` pointer and value need to be represented by another trait.
2.
Closures are types, so they cannot be returned directly from a function.
3.
Closures are types and can be returned only if the concrete trait is implemented.
4.
Closures are represented by traits, so they cannot be a return type.
Q 23 / 32
1.
`Arc<T>`
2.
`Box<T>`
3.
Both `Arc<T>` and `Rc<T>` are multithread safe.
4.
`Rc<T>`
Q 24 / 32
1.
zero-sized types
2.
structs
3.
trait objects
4.
floating-point numbers
Q 25 / 32
rust fn main() { let c = 'z'; let heart_eyed_cat = '😻'; }
1.
Both are character literals.
2.
`heart_eyed_cat` is an invalid expression.
3.
`c` is a string literal and `heart_eyed_cat` is a character literal.
4.
Both are string literals.
Q 26 / 32
1.
`Mutex<Arc<T>>`
2.
`Rc<Mutex<T>>`
3.
`Arc<Mutex<T>>`
4.
`Mutex<Rc<T>>`
Q 27 / 32
rust let a = "a".to_string(); let b = "b".to_string(); let c = "c".to_string();
1.
`String::from(a,b,c)`
2.
`format!("{}{}{}", a, b, c)`
3.
`concat(a,b,c)`
4.
`a + b + c`
Q 28 / 32
rust use std::fmt::Debug; fn report<T:Debug>(a: &T) { eprintln!("info: {:?}", a); }
1.
2.
read-only
3.
read/write
4.
debug
Q 29 / 32
1.
`loop`
2.
`for`
3.
`while`
4.
`do`
Q 30 / 32
rust enum Status { Waiting, Busy, Error(String), }
1.
`let s = Enum::new(Status::Waiting);`
2.
`let s = new Status::Waiting;`
3.
`let s = Status::Waiting;`
4.
`let s = Status::new(Waiting);`
Q 31 / 32
1.
Enums are useful in matching patterns.
2.
Option is an enum type.
3.
Enum variants can have different types with associated data.
4.
the term _enum_ is short for _enummap_
Q 32 / 32