str::thread::spawn(|| {
println!("LinkedIn");
});
cargo command checks a program for error without creating a binary executable?slice that produces the same result?...
let s = String::form("hello");
let slice = &s[0..2];
? operator at the end of an expression is equivalent to _.fn increment(i: T) {
// body elided
}
/*#//!//.ignore()an underscore (_)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);
}
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);
main function compile? If so, why? If not, what do you need to change?fn main() {
let Some(x) = some_option_value;
}
let statements require a refutable pattern. Add if before let.let statements sometimes require a refutable pattern.let statements requires an irrefutable pattern. Add if before let.let do not require a refutable pattern.None, JavaScript’s null, or the void type in C/C++?!NoneNull()Result to an Option, which method should you use?.as_option().ok().to_option().into()Clone and Copy traits is false?Copy is enabled for primitive, built-in types.Copy, Rust applies move semantics to a type’s access.Clone, copying data is explicit.Copy or Clone, its internal data cannot be copied.fn returns_closure() -> dyn Fn(i32) -> i32 {
|x| x + 1
}
fn pointer and value need to be represented by another trait.Arc<T>Box<T>Arc<T> and Rc<T> are multithread safe.Rc<T>fn main() {
let c = 'z';
let heart_eyed_cat = '😻';
}
heart_eyed_cat is an invalid expression.c is a string literal and heart_eyed_cat is a character literal.Mutex<Arc<T>>Rc<Mutex<T>>Arc<Mutex<T>>Mutex<Rc<T>>a, b, c?let a = "a".to_string();
let b = "b".to_string();
let c = "c".to_string();
String::from(a,b,c)format!("{}{}{}", a, b, c)concat(a,b,c)a + b + ca?use std::fmt::Debug;
fn report<T:Debug>(a: &T) {
eprintln!("info: {:?}", a);
}
loopforwhiledoStatus that is initialized to Waiting?enum Status {
Waiting,
Busy,
Error(String),
}
let s = Enum::new(Status::Waiting);let s = new Status::Waiting;let s = Status::Waiting;let s = Status::new(Waiting);std::cell:UnsafeCell<T>?&mut T reference is allowed. However it may not cpexists with any other references. and may be created only in single-threaded code.UnsafeCell<T> provides thread-safety. Therefore, creating &T references from multiple threads is safe..get() method, which returns only a raw pointer.UnsafeCell<T> only allows code that would otherwise need unsafe blocks to be written in safe code.let text = String::new("LinkedIn");
enum Option_i32 {
Some(i32),
None,
}
if x {
println!("ok");
}
struct person = Person {
height: u64,
weight: u64,
married: bool
}
fn main() {
let x = 5;
println!("The value of x is: {}", x);
x = 6;
println!("The value of x is: {}", x);
}
let pt = Point2D(-1.0, 2.0)
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);
}
Result to an Option, which method should you use?.as_option().ok().to_option().into()fn main() {
let c = 'z';
let heart_eyed_cat = '😻';
}
heart_eyed_cat is an invalid expression.c is a string literal and heart_eyed_cat is a character literal.slice that produces the same result?...
let s = String::form("hello");
let slice = &s[0..2];
let pt = Point2D(-1.0, 2.0)