mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-11 21:29:18 +00:00
all
This commit is contained in:
parent
d57c183028
commit
85e533e746
@ -24,12 +24,18 @@ impl From<CreationError> for ParsePosNonzeroError {
|
|||||||
fn from(e: CreationError) -> Self {
|
fn from(e: CreationError) -> Self {
|
||||||
// TODO: complete this implementation so that the `?` operator will
|
// TODO: complete this implementation so that the `?` operator will
|
||||||
// work for `CreationError`
|
// work for `CreationError`
|
||||||
|
Self::Creation(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: implement another instance of the `From` trait here so that the
|
// TODO: implement another instance of the `From` trait here so that the
|
||||||
// `?` operator will work in the other place in the `FromStr`
|
// `?` operator will work in the other place in the `FromStr`
|
||||||
// implementation below.
|
// implementation below.
|
||||||
|
impl From<ParseIntError> for ParsePosNonzeroError {
|
||||||
|
fn from(e: ParseIntError) -> Self {
|
||||||
|
Self::ParseInt(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Don't change anything below this line.
|
// Don't change anything below this line.
|
||||||
|
|
||||||
|
|||||||
@ -47,9 +47,14 @@ impl From<ParseIntError> for ParseClimateError {
|
|||||||
impl From<ParseFloatError> for ParseClimateError {
|
impl From<ParseFloatError> for ParseClimateError {
|
||||||
fn from(e: ParseFloatError) -> Self {
|
fn from(e: ParseFloatError) -> Self {
|
||||||
// TODO: Complete this function
|
// TODO: Complete this function
|
||||||
|
Self::ParseFloat(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for ParseClimateError {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Implement a missing trait so that `main()` below will compile. It
|
// TODO: Implement a missing trait so that `main()` below will compile. It
|
||||||
// is not necessary to implement any methods inside the missing trait.
|
// is not necessary to implement any methods inside the missing trait.
|
||||||
|
|
||||||
@ -63,7 +68,10 @@ impl Display for ParseClimateError {
|
|||||||
use ParseClimateError::*;
|
use ParseClimateError::*;
|
||||||
match self {
|
match self {
|
||||||
NoCity => write!(f, "no city name"),
|
NoCity => write!(f, "no city name"),
|
||||||
|
BadLen => write!(f, "incorrect number of fields"),
|
||||||
|
Empty => write!(f, "empty input"),
|
||||||
ParseFloat(e) => write!(f, "error parsing temperature: {}", e),
|
ParseFloat(e) => write!(f, "error parsing temperature: {}", e),
|
||||||
|
ParseInt(e) => write!(f, "error parsing year: {}", e),
|
||||||
_ => write!(f, "unhandled error!"),
|
_ => write!(f, "unhandled error!"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,11 +98,19 @@ impl FromStr for Climate {
|
|||||||
// cases.
|
// cases.
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
let v: Vec<_> = s.split(',').collect();
|
let v: Vec<_> = s.split(',').collect();
|
||||||
let (city, year, temp) = match &v[..] {
|
let (city, yr, temp) = match &v[..] {
|
||||||
[city, year, temp] => (city.to_string(), year, temp),
|
[city, year, temp] => (city.to_string(), year, temp),
|
||||||
|
[""] => return Err(ParseClimateError::Empty),
|
||||||
_ => return Err(ParseClimateError::BadLen),
|
_ => return Err(ParseClimateError::BadLen),
|
||||||
};
|
};
|
||||||
let year: u32 = year.parse()?;
|
if city.is_empty() {
|
||||||
|
return Err(ParseClimateError::NoCity);
|
||||||
|
}
|
||||||
|
let year: u32;
|
||||||
|
match yr.parse::<u32>() {
|
||||||
|
Ok(y) => year = y,
|
||||||
|
Err(e) => return Err(ParseClimateError::ParseInt(e))
|
||||||
|
}
|
||||||
let temp: f32 = temp.parse()?;
|
let temp: f32 = temp.parse()?;
|
||||||
Ok(Climate { city, year, temp })
|
Ok(Climate { city, year, temp })
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
let mut res = 42;
|
let mut res = 42;
|
||||||
let option = Some(12);
|
let option = Some(12);
|
||||||
for x in option {
|
if let Some(x) = option {
|
||||||
res += x;
|
res += x;
|
||||||
}
|
}
|
||||||
println!("{}", res);
|
println!("{}", res);
|
||||||
|
|||||||
@ -16,12 +16,14 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
fn fruit_basket() -> HashMap<String, u32> {
|
fn fruit_basket() -> HashMap<String, u32> {
|
||||||
let mut basket = // TODO: declare your hash map here.
|
let mut basket = HashMap::new();
|
||||||
|
|
||||||
// Two bananas are already given for you :)
|
// Two bananas are already given for you :)
|
||||||
basket.insert(String::from("banana"), 2);
|
basket.insert(String::from("banana"), 2);
|
||||||
|
|
||||||
// TODO: Put more fruits in your basket here.
|
// TODO: Put more fruits in your basket here.
|
||||||
|
basket.insert(String::from("apple"), 2);
|
||||||
|
basket.insert(String::from("peach"), 3);
|
||||||
|
|
||||||
basket
|
basket
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,6 +38,7 @@ fn fruit_basket(basket: &mut HashMap<Fruit, u32>) {
|
|||||||
// TODO: Put new fruits if not already present. Note that you
|
// TODO: Put new fruits if not already present. Note that you
|
||||||
// are not allowed to put any type of fruit that's already
|
// are not allowed to put any type of fruit that's already
|
||||||
// present!
|
// present!
|
||||||
|
basket.entry(fruit).or_insert(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
fn array_and_vec() -> ([i32; 4], Vec<i32>) {
|
fn array_and_vec() -> ([i32; 4], Vec<i32>) {
|
||||||
let a = [10, 20, 30, 40]; // a plain array
|
let a = [10, 20, 30, 40]; // a plain array
|
||||||
let v = // TODO: declare your vector here with the macro for vectors
|
let v = vec![10, 20, 30, 40];// TODO: declare your vector here with the macro for vectors
|
||||||
|
|
||||||
(a, v)
|
(a, v)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,6 +13,7 @@ fn vec_loop(mut v: Vec<i32>) -> Vec<i32> {
|
|||||||
for i in v.iter_mut() {
|
for i in v.iter_mut() {
|
||||||
// TODO: Fill this up so that each element in the Vec `v` is
|
// TODO: Fill this up so that each element in the Vec `v` is
|
||||||
// multiplied by 2.
|
// multiplied by 2.
|
||||||
|
*i *= 2
|
||||||
}
|
}
|
||||||
|
|
||||||
// At this point, `v` should be equal to [4, 8, 12, 16, 20].
|
// At this point, `v` should be equal to [4, 8, 12, 16, 20].
|
||||||
|
|||||||
@ -6,13 +6,15 @@
|
|||||||
|
|
||||||
// Obtain the number of bytes (not characters) in the given argument
|
// Obtain the number of bytes (not characters) in the given argument
|
||||||
// Add the AsRef trait appropriately as a trait bound
|
// Add the AsRef trait appropriately as a trait bound
|
||||||
fn byte_counter<T>(arg: T) -> usize {
|
fn byte_counter<T>(arg: T) -> usize
|
||||||
|
where T: AsRef<str> {
|
||||||
arg.as_ref().as_bytes().len()
|
arg.as_ref().as_bytes().len()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtain the number of characters (not bytes) in the given argument
|
// Obtain the number of characters (not bytes) in the given argument
|
||||||
// Add the AsRef trait appropriately as a trait bound
|
// Add the AsRef trait appropriately as a trait bound
|
||||||
fn char_counter<T>(arg: T) -> usize {
|
fn char_counter<T>(arg: T) -> usize
|
||||||
|
where T: AsRef<str> {
|
||||||
arg.as_ref().chars().count()
|
arg.as_ref().chars().count()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -37,6 +37,24 @@ impl Default for Person {
|
|||||||
|
|
||||||
impl From<&str> for Person {
|
impl From<&str> for Person {
|
||||||
fn from(s: &str) -> Person {
|
fn from(s: &str) -> Person {
|
||||||
|
let v: Vec<_> = s.split(",").collect();
|
||||||
|
// println!("{:?}", v);
|
||||||
|
let (name, age) = match &v[..] {
|
||||||
|
["", _] => return Default::default(),
|
||||||
|
[_, ""] => return Default::default(),
|
||||||
|
[name, age] => (name.to_string(), age),
|
||||||
|
_ => return Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let age: usize = match age.parse() {
|
||||||
|
Ok(age) => age,
|
||||||
|
_ => return Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
Self {
|
||||||
|
name,
|
||||||
|
age
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -41,6 +41,22 @@ enum ParsePersonError {
|
|||||||
impl FromStr for Person {
|
impl FromStr for Person {
|
||||||
type Err = ParsePersonError;
|
type Err = ParsePersonError;
|
||||||
fn from_str(s: &str) -> Result<Person, Self::Err> {
|
fn from_str(s: &str) -> Result<Person, Self::Err> {
|
||||||
|
let v: Vec<_> = s.split(",").collect();
|
||||||
|
let (name, age) = match &v[..] {
|
||||||
|
[""] => return Err(ParsePersonError::Empty),
|
||||||
|
["", _] => return Err(ParsePersonError::NoName),
|
||||||
|
[name, age] => (name.to_string(), age),
|
||||||
|
_ => return Err(ParsePersonError::BadLen)
|
||||||
|
};
|
||||||
|
|
||||||
|
let age: usize = match age.parse() {
|
||||||
|
Ok(age) => age,
|
||||||
|
Err(e) => return Err(ParsePersonError::ParseInt(e))
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(Self {
|
||||||
|
name, age
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -36,6 +36,24 @@ enum IntoColorError {
|
|||||||
impl TryFrom<(i16, i16, i16)> for Color {
|
impl TryFrom<(i16, i16, i16)> for Color {
|
||||||
type Error = IntoColorError;
|
type Error = IntoColorError;
|
||||||
fn try_from(tuple: (i16, i16, i16)) -> Result<Self, Self::Error> {
|
fn try_from(tuple: (i16, i16, i16)) -> Result<Self, Self::Error> {
|
||||||
|
let red = match u8::try_from(tuple.0) {
|
||||||
|
Ok(red) => red,
|
||||||
|
_ => return Err(Self::Error::IntConversion),
|
||||||
|
};
|
||||||
|
|
||||||
|
let green = match u8::try_from(tuple.1) {
|
||||||
|
Ok(green) => green,
|
||||||
|
_ => return Err(Self::Error::IntConversion),
|
||||||
|
};
|
||||||
|
|
||||||
|
let blue = match u8::try_from(tuple.2) {
|
||||||
|
Ok(blue) => blue,
|
||||||
|
_ => return Err(Self::Error::IntConversion),
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(Self {
|
||||||
|
red, green, blue
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,6 +61,7 @@ impl TryFrom<(i16, i16, i16)> for Color {
|
|||||||
impl TryFrom<[i16; 3]> for Color {
|
impl TryFrom<[i16; 3]> for Color {
|
||||||
type Error = IntoColorError;
|
type Error = IntoColorError;
|
||||||
fn try_from(arr: [i16; 3]) -> Result<Self, Self::Error> {
|
fn try_from(arr: [i16; 3]) -> Result<Self, Self::Error> {
|
||||||
|
Self::try_from((arr[0], arr[1], arr[2]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,6 +69,11 @@ impl TryFrom<[i16; 3]> for Color {
|
|||||||
impl TryFrom<&[i16]> for Color {
|
impl TryFrom<&[i16]> for Color {
|
||||||
type Error = IntoColorError;
|
type Error = IntoColorError;
|
||||||
fn try_from(slice: &[i16]) -> Result<Self, Self::Error> {
|
fn try_from(slice: &[i16]) -> Result<Self, Self::Error> {
|
||||||
|
if slice.len() != 3 {
|
||||||
|
return Err(Self::Error::BadLen);
|
||||||
|
}
|
||||||
|
|
||||||
|
Self::try_from((slice[0], slice[1], slice[2]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
fn average(values: &[f64]) -> f64 {
|
fn average(values: &[f64]) -> f64 {
|
||||||
let total = values.iter().fold(0.0, |a, b| a + b);
|
let total = values.iter().fold(0.0, |a, b| a + b);
|
||||||
total / values.len()
|
total / (values.len() as f64)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|||||||
@ -6,6 +6,10 @@
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum Message {
|
enum Message {
|
||||||
// TODO: define a few types of messages as used below
|
// TODO: define a few types of messages as used below
|
||||||
|
Quit,
|
||||||
|
Echo,
|
||||||
|
Move,
|
||||||
|
ChangeColor,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|||||||
@ -6,6 +6,10 @@
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum Message {
|
enum Message {
|
||||||
// TODO: define the different variants used below
|
// TODO: define the different variants used below
|
||||||
|
Move {x: i32, y: i32},
|
||||||
|
Echo (String),
|
||||||
|
ChangeColor (i32, i32, i32),
|
||||||
|
Quit,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Message {
|
impl Message {
|
||||||
|
|||||||
@ -2,11 +2,15 @@
|
|||||||
// Address all the TODOs to make the tests pass!
|
// Address all the TODOs to make the tests pass!
|
||||||
|
|
||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
#[derive(Debug)]
|
||||||
enum Message {
|
enum Message {
|
||||||
// TODO: implement the message variant types based on their usage below
|
// TODO: implement the message variant types based on their usage below
|
||||||
|
ChangeColor((u8, u8, u8)),
|
||||||
|
Echo(String),
|
||||||
|
Move(Point),
|
||||||
|
Quit,
|
||||||
}
|
}
|
||||||
|
#[derive(Debug)]
|
||||||
struct Point {
|
struct Point {
|
||||||
x: u8,
|
x: u8,
|
||||||
y: u8,
|
y: u8,
|
||||||
@ -37,6 +41,20 @@ impl State {
|
|||||||
|
|
||||||
fn process(&mut self, message: Message) {
|
fn process(&mut self, message: Message) {
|
||||||
// TODO: create a match expression to process the different message variants
|
// TODO: create a match expression to process the different message variants
|
||||||
|
match message {
|
||||||
|
Message::ChangeColor((x, y, z)) => {
|
||||||
|
self.color = (x, y, z);
|
||||||
|
},
|
||||||
|
Message::Move(p) => {
|
||||||
|
self.position = p;
|
||||||
|
},
|
||||||
|
Message::Quit => {
|
||||||
|
self.quit = true;
|
||||||
|
},
|
||||||
|
Message::Echo(s) => {
|
||||||
|
println!("{}", s);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,12 +8,12 @@
|
|||||||
|
|
||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
pub fn generate_nametag_text(name: String) -> Option<String> {
|
pub fn generate_nametag_text(name: String) -> Result<String, String> {
|
||||||
if name.len() > 0 {
|
if name.len() > 0 {
|
||||||
Some(format!("Hi! My name is {}", name))
|
Ok(format!("Hi! My name is {}", name))
|
||||||
} else {
|
} else {
|
||||||
// Empty names aren't allowed.
|
// Empty names aren't allowed.
|
||||||
None
|
Err("`name` was empty; it must be nonempty.".to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ mod tests {
|
|||||||
fn generates_nametag_text_for_a_nonempty_name() {
|
fn generates_nametag_text_for_a_nonempty_name() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
generate_nametag_text("Beyoncé".into()),
|
generate_nametag_text("Beyoncé".into()),
|
||||||
Some("Hi! My name is Beyoncé".into())
|
Ok("Hi! My name is Beyoncé".into())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,9 +23,12 @@ use std::num::ParseIntError;
|
|||||||
pub fn total_cost(item_quantity: &str) -> Result<i32, ParseIntError> {
|
pub fn total_cost(item_quantity: &str) -> Result<i32, ParseIntError> {
|
||||||
let processing_fee = 1;
|
let processing_fee = 1;
|
||||||
let cost_per_item = 5;
|
let cost_per_item = 5;
|
||||||
let qty = item_quantity.parse::<i32>();
|
match item_quantity.parse::<i32>() {
|
||||||
|
Ok(qty) => {
|
||||||
Ok(qty * cost_per_item + processing_fee)
|
Ok(qty * cost_per_item + processing_fee)
|
||||||
|
},
|
||||||
|
e => e
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@ -12,7 +12,7 @@ fn main() {
|
|||||||
let mut tokens = 100;
|
let mut tokens = 100;
|
||||||
let pretend_user_input = "8";
|
let pretend_user_input = "8";
|
||||||
|
|
||||||
let cost = total_cost(pretend_user_input)?;
|
let cost = total_cost(pretend_user_input).unwrap();
|
||||||
|
|
||||||
if cost > tokens {
|
if cost > tokens {
|
||||||
println!("You can't afford that many!");
|
println!("You can't afford that many!");
|
||||||
@ -25,7 +25,8 @@ fn main() {
|
|||||||
pub fn total_cost(item_quantity: &str) -> Result<i32, ParseIntError> {
|
pub fn total_cost(item_quantity: &str) -> Result<i32, ParseIntError> {
|
||||||
let processing_fee = 1;
|
let processing_fee = 1;
|
||||||
let cost_per_item = 5;
|
let cost_per_item = 5;
|
||||||
let qty = item_quantity.parse::<i32>()?;
|
match item_quantity.parse::<i32>() {
|
||||||
|
Ok(qty) => Ok(qty * cost_per_item + processing_fee),
|
||||||
Ok(qty * cost_per_item + processing_fee)
|
e => e
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,7 +14,13 @@ enum CreationError {
|
|||||||
|
|
||||||
impl PositiveNonzeroInteger {
|
impl PositiveNonzeroInteger {
|
||||||
fn new(value: i64) -> Result<PositiveNonzeroInteger, CreationError> {
|
fn new(value: i64) -> Result<PositiveNonzeroInteger, CreationError> {
|
||||||
Ok(PositiveNonzeroInteger(value as u64))
|
if value < 0 {
|
||||||
|
Err(CreationError::Negative)
|
||||||
|
} else if value == 0 {
|
||||||
|
Err(CreationError::Zero)
|
||||||
|
} else {
|
||||||
|
Ok(PositiveNonzeroInteger(value as u64))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,7 @@ use std::fmt;
|
|||||||
use std::num::ParseIntError;
|
use std::num::ParseIntError;
|
||||||
|
|
||||||
// TODO: update the return type of `main()` to make this compile.
|
// TODO: update the return type of `main()` to make this compile.
|
||||||
fn main() -> Result<(), ParseIntError> {
|
fn main() -> Result<(), Box<dyn error::Error>> {
|
||||||
let pretend_user_input = "42";
|
let pretend_user_input = "42";
|
||||||
let x: i64 = pretend_user_input.parse()?;
|
let x: i64 = pretend_user_input.parse()?;
|
||||||
println!("output={:?}", PositiveNonzeroInteger::new(x)?);
|
println!("output={:?}", PositiveNonzeroInteger::new(x)?);
|
||||||
|
|||||||
@ -24,6 +24,9 @@ impl ParsePosNonzeroError {
|
|||||||
ParsePosNonzeroError::Creation(err)
|
ParsePosNonzeroError::Creation(err)
|
||||||
}
|
}
|
||||||
// TODO: add another error conversion function here.
|
// TODO: add another error conversion function here.
|
||||||
|
fn from_parseint(err: ParseIntError) -> ParsePosNonzeroError {
|
||||||
|
ParsePosNonzeroError::ParseInt(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_pos_nonzero(s: &str)
|
fn parse_pos_nonzero(s: &str)
|
||||||
@ -31,9 +34,15 @@ fn parse_pos_nonzero(s: &str)
|
|||||||
{
|
{
|
||||||
// TODO: change this to return an appropriate error instead of panicking
|
// TODO: change this to return an appropriate error instead of panicking
|
||||||
// when `parse()` returns an error.
|
// when `parse()` returns an error.
|
||||||
let x: i64 = s.parse().unwrap();
|
match s.parse() {
|
||||||
PositiveNonzeroInteger::new(x)
|
Ok(x) => {
|
||||||
.map_err(ParsePosNonzeroError::from_creation)
|
match PositiveNonzeroInteger::new(x) {
|
||||||
|
Ok(pni) => Ok(pni),
|
||||||
|
Err(e) => Err(ParsePosNonzeroError::from_creation(e))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(e) => Err(ParsePosNonzeroError::from_parseint(e))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't change anything below this line.
|
// Don't change anything below this line.
|
||||||
|
|||||||
@ -3,6 +3,10 @@
|
|||||||
|
|
||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
|
fn call_me() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
call_me();
|
call_me();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,7 @@ fn main() {
|
|||||||
call_me(3);
|
call_me(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call_me(num:) {
|
fn call_me(num: i32) {
|
||||||
for i in 0..num {
|
for i in 0..num {
|
||||||
println!("Ring! Call number {}", i + 1);
|
println!("Ring! Call number {}", i + 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
call_me();
|
call_me(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call_me(num: u32) {
|
fn call_me(num: u32) {
|
||||||
|
|||||||
@ -11,7 +11,7 @@ fn main() {
|
|||||||
println!("Your sale price is {}", sale_price(original_price));
|
println!("Your sale price is {}", sale_price(original_price));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sale_price(price: i32) -> {
|
fn sale_price(price: i32) -> i32 {
|
||||||
if is_even(price) {
|
if is_even(price) {
|
||||||
price - 10
|
price - 10
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -9,5 +9,5 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn square(num: i32) -> i32 {
|
fn square(num: i32) -> i32 {
|
||||||
num * num;
|
num * num
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,6 @@
|
|||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut shopping_list: Vec<?> = Vec::new();
|
let mut shopping_list: Vec<&str> = Vec::new();
|
||||||
shopping_list.push("milk");
|
shopping_list.push("milk");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,12 +5,12 @@
|
|||||||
|
|
||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
struct Wrapper {
|
struct Wrapper<T> {
|
||||||
value: u32,
|
value: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Wrapper {
|
impl<T> Wrapper<T> {
|
||||||
pub fn new(value: u32) -> Self {
|
pub fn new(value: T) -> Self {
|
||||||
Wrapper { value }
|
Wrapper { value }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,13 +12,13 @@
|
|||||||
|
|
||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
pub struct ReportCard {
|
pub struct ReportCard<T> {
|
||||||
pub grade: f32,
|
pub grade: T,
|
||||||
pub student_name: String,
|
pub student_name: String,
|
||||||
pub student_age: u8,
|
pub student_age: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ReportCard {
|
impl<T: std::fmt::Display> ReportCard<T> {
|
||||||
pub fn print(&self) -> String {
|
pub fn print(&self) -> String {
|
||||||
format!("{} ({}) - achieved a grade of {}",
|
format!("{} ({}) - achieved a grade of {}",
|
||||||
&self.student_name, &self.student_age, &self.grade)
|
&self.student_name, &self.student_age, &self.grade)
|
||||||
@ -46,7 +46,7 @@ mod tests {
|
|||||||
fn generate_alphabetic_report_card() {
|
fn generate_alphabetic_report_card() {
|
||||||
// TODO: Make sure to change the grade here after you finish the exercise.
|
// TODO: Make sure to change the grade here after you finish the exercise.
|
||||||
let report_card = ReportCard {
|
let report_card = ReportCard {
|
||||||
grade: 2.1,
|
grade: "A+",
|
||||||
student_name: "Gary Plotter".to_string(),
|
student_name: "Gary Plotter".to_string(),
|
||||||
student_age: 11,
|
student_age: 11,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -8,6 +8,11 @@ pub fn bigger(a: i32, b: i32) -> i32 {
|
|||||||
// - another function call
|
// - another function call
|
||||||
// - additional variables
|
// - additional variables
|
||||||
// Execute `rustlings hint if1` for hints
|
// Execute `rustlings hint if1` for hints
|
||||||
|
if a > b {
|
||||||
|
a
|
||||||
|
} else {
|
||||||
|
b
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't mind this for now :)
|
// Don't mind this for now :)
|
||||||
|
|||||||
@ -9,8 +9,10 @@
|
|||||||
pub fn fizz_if_foo(fizzish: &str) -> &str {
|
pub fn fizz_if_foo(fizzish: &str) -> &str {
|
||||||
if fizzish == "fizz" {
|
if fizzish == "fizz" {
|
||||||
"foo"
|
"foo"
|
||||||
|
} else if fizzish == "fuzz" {
|
||||||
|
"bar"
|
||||||
} else {
|
} else {
|
||||||
1
|
"baz"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
macro_rules! my_macro {
|
macro_rules! my_macro {
|
||||||
() => {
|
() => {
|
||||||
println!("Check out my macro!");
|
println!("Check out my macro!");
|
||||||
@ -10,5 +11,5 @@ macro_rules! my_macro {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
my_macro();
|
my_macro!();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,7 @@ fn main() {
|
|||||||
my_macro!();
|
my_macro!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
macro_rules! my_macro {
|
macro_rules! my_macro {
|
||||||
() => {
|
() => {
|
||||||
println!("Check out my macro!");
|
println!("Check out my macro!");
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
mod macros {
|
mod macros {
|
||||||
macro_rules! my_macro {
|
macro_rules! my_macro {
|
||||||
() => {
|
() => {
|
||||||
|
|||||||
@ -6,10 +6,10 @@
|
|||||||
macro_rules! my_macro {
|
macro_rules! my_macro {
|
||||||
() => {
|
() => {
|
||||||
println!("Check out my macro!");
|
println!("Check out my macro!");
|
||||||
}
|
};
|
||||||
($val:expr) => {
|
($val:expr) => {
|
||||||
println!("Look at this other macro: {}", $val);
|
println!("Look at this other macro: {}", $val);
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|||||||
@ -9,7 +9,7 @@ mod sausage_factory {
|
|||||||
String::from("Ginger")
|
String::from("Ginger")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_sausage() {
|
pub fn make_sausage() {
|
||||||
get_secret_recipe();
|
get_secret_recipe();
|
||||||
println!("sausage!");
|
println!("sausage!");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,8 +8,8 @@
|
|||||||
mod delicious_snacks {
|
mod delicious_snacks {
|
||||||
|
|
||||||
// TODO: Fix these use statements
|
// TODO: Fix these use statements
|
||||||
use self::fruits::PEAR as ???
|
pub use self::fruits::PEAR as fruit;
|
||||||
use self::veggies::CUCUMBER as ???
|
pub use self::veggies::CUCUMBER as veggie;
|
||||||
|
|
||||||
mod fruits {
|
mod fruits {
|
||||||
pub const PEAR: &'static str = "Pear";
|
pub const PEAR: &'static str = "Pear";
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
// TODO: Complete this use statement
|
// TODO: Complete this use statement
|
||||||
use ???
|
use std::time::{ SystemTime, UNIX_EPOCH };
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
match SystemTime::now().duration_since(UNIX_EPOCH) {
|
match SystemTime::now().duration_since(UNIX_EPOCH) {
|
||||||
|
|||||||
@ -4,9 +4,9 @@
|
|||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let vec0 = Vec::new();
|
let mut vec0 = Vec::new();
|
||||||
|
|
||||||
let vec1 = fill_vec(vec0);
|
let mut vec1 = fill_vec(vec0);
|
||||||
|
|
||||||
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
|
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
|
||||||
|
|
||||||
@ -15,8 +15,7 @@ fn main() {
|
|||||||
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
|
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
|
fn fill_vec(mut vec: Vec<i32>) -> Vec<i32> {
|
||||||
let mut vec = vec;
|
|
||||||
|
|
||||||
vec.push(22);
|
vec.push(22);
|
||||||
vec.push(44);
|
vec.push(44);
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
let vec0 = Vec::new();
|
let vec0 = Vec::new();
|
||||||
|
|
||||||
let mut vec1 = fill_vec(vec0);
|
let mut vec1 = fill_vec(&vec0);
|
||||||
|
|
||||||
// Do not change the following line!
|
// Do not change the following line!
|
||||||
println!("{} has length {} content `{:?}`", "vec0", vec0.len(), vec0);
|
println!("{} has length {} content `{:?}`", "vec0", vec0.len(), vec0);
|
||||||
@ -17,8 +17,8 @@ fn main() {
|
|||||||
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
|
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
|
fn fill_vec(vec: &Vec<i32>) -> Vec<i32> {
|
||||||
let mut vec = vec;
|
let mut vec = vec.clone();
|
||||||
|
|
||||||
vec.push(22);
|
vec.push(22);
|
||||||
vec.push(44);
|
vec.push(44);
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let vec0 = Vec::new();
|
let mut vec0 = Vec::new();
|
||||||
|
|
||||||
let mut vec1 = fill_vec(vec0);
|
let mut vec1 = fill_vec(vec0);
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ fn main() {
|
|||||||
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
|
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
|
fn fill_vec(mut vec: Vec<i32>) -> Vec<i32> {
|
||||||
vec.push(22);
|
vec.push(22);
|
||||||
vec.push(44);
|
vec.push(44);
|
||||||
vec.push(66);
|
vec.push(66);
|
||||||
|
|||||||
@ -7,9 +7,8 @@
|
|||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let vec0 = Vec::new();
|
|
||||||
|
|
||||||
let mut vec1 = fill_vec(vec0);
|
let mut vec1 = fill_vec();
|
||||||
|
|
||||||
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
|
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
|
||||||
|
|
||||||
@ -20,7 +19,7 @@ fn main() {
|
|||||||
|
|
||||||
// `fill_vec()` no longer takes `vec: Vec<i32>` as argument
|
// `fill_vec()` no longer takes `vec: Vec<i32>` as argument
|
||||||
fn fill_vec() -> Vec<i32> {
|
fn fill_vec() -> Vec<i32> {
|
||||||
let mut vec = vec;
|
let mut vec = Vec::new();
|
||||||
|
|
||||||
vec.push(22);
|
vec.push(22);
|
||||||
vec.push(44);
|
vec.push(44);
|
||||||
|
|||||||
@ -8,8 +8,8 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
let mut x = 100;
|
let mut x = 100;
|
||||||
let y = &mut x;
|
let y = &mut x;
|
||||||
let z = &mut x;
|
|
||||||
*y += 100;
|
*y += 100;
|
||||||
|
let z = &mut x;
|
||||||
*z += 1000;
|
*z += 1000;
|
||||||
assert_eq!(x, 1200);
|
assert_eq!(x, 1200);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,15 +9,15 @@ fn print_number(maybe_number: Option<u16>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
print_number(13);
|
print_number(Some(13));
|
||||||
print_number(99);
|
print_number(Some(99));
|
||||||
|
|
||||||
let mut numbers: [Option<u16>; 5];
|
let mut numbers: [Option<u16>; 5] = [None; 5];
|
||||||
for iter in 0..5 {
|
for iter in 0..5 {
|
||||||
let number_to_add: u16 = {
|
let number_to_add: u16 = {
|
||||||
((iter * 1235) + 2) / (4 * 16)
|
((iter * 1235) + 2) / (4 * 16)
|
||||||
};
|
};
|
||||||
|
|
||||||
numbers[iter as usize] = number_to_add;
|
numbers[iter as usize] = Some(number_to_add);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
let optional_word = Some(String::from("rustlings"));
|
let optional_word = Some(String::from("rustlings"));
|
||||||
// TODO: Make this an if let statement whose value is "Some" type
|
// TODO: Make this an if let statement whose value is "Some" type
|
||||||
word = optional_word {
|
if let Some(word) = optional_word {
|
||||||
println!("The word is: {}", word);
|
println!("The word is: {}", word);
|
||||||
} else {
|
} else {
|
||||||
println!("The optional word doesn't contain anything");
|
println!("The optional word doesn't contain anything");
|
||||||
@ -19,7 +19,7 @@ fn main() {
|
|||||||
|
|
||||||
// TODO: make this a while let statement - remember that vector.pop also adds another layer of Option<T>
|
// TODO: make this a while let statement - remember that vector.pop also adds another layer of Option<T>
|
||||||
// You can stack `Option<T>`'s into while let and if let
|
// You can stack `Option<T>`'s into while let and if let
|
||||||
integer = optional_integers_vec.pop() {
|
while let Some(Some(integer)) = optional_integers_vec.pop() {
|
||||||
println!("current value: {}", integer);
|
println!("current value: {}", integer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,9 +11,14 @@ struct Point {
|
|||||||
fn main() {
|
fn main() {
|
||||||
let y: Option<Point> = Some(Point { x: 100, y: 200 });
|
let y: Option<Point> = Some(Point { x: 100, y: 200 });
|
||||||
|
|
||||||
match y {
|
match y.as_ref() {
|
||||||
Some(p) => println!("Co-ordinates are {},{} ", p.x, p.y),
|
Some(p) => println!("Co-ordinates are {},{} ", p.x, p.y),
|
||||||
_ => println!("no match"),
|
_ => println!("no match"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
match y {
|
||||||
|
Some(ref p) => println!("Co-ordinates are {},{} ", p.x, p.y),
|
||||||
|
_ => println!("no match"),
|
||||||
|
}
|
||||||
y; // Fix without deleting this line.
|
y; // Fix without deleting this line.
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,7 +12,7 @@ fn main() {
|
|||||||
println!("Good morning!");
|
println!("Good morning!");
|
||||||
}
|
}
|
||||||
|
|
||||||
let // Finish the rest of this line like the example! Or make it be false!
|
let is_evening = true; // Finish the rest of this line like the example! Or make it be false!
|
||||||
if is_evening {
|
if is_evening {
|
||||||
println!("Good evening!");
|
println!("Good evening!");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
// primitive_types2.rs
|
|
||||||
// Fill in the rest of the line that has code missing!
|
// Fill in the rest of the line that has code missing!
|
||||||
// No hints, there's no tricks, just get used to typing these :)
|
// No hints, there's no tricks, just get used to typing these :)
|
||||||
|
|
||||||
@ -16,7 +15,7 @@ fn main() {
|
|||||||
println!("Neither alphabetic nor numeric!");
|
println!("Neither alphabetic nor numeric!");
|
||||||
}
|
}
|
||||||
|
|
||||||
let // Finish this line like the example! What's your favorite character?
|
let your_character = '😊'; // Finish this line like the example! What's your favorite character?
|
||||||
// Try a letter, try a number, try a special character, try a character
|
// Try a letter, try a number, try a special character, try a character
|
||||||
// from a different language than your own, try an emoji!
|
// from a different language than your own, try an emoji!
|
||||||
if your_character.is_alphabetic() {
|
if your_character.is_alphabetic() {
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let a = ???
|
let a = [1; 100];
|
||||||
|
|
||||||
if a.len() >= 100 {
|
if a.len() >= 100 {
|
||||||
println!("Wow, that's a big array!");
|
println!("Wow, that's a big array!");
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
fn slice_out_of_array() {
|
fn slice_out_of_array() {
|
||||||
let a = [1, 2, 3, 4, 5];
|
let a = [1, 2, 3, 4, 5];
|
||||||
|
|
||||||
let nice_slice = ???
|
let nice_slice = &a[1..4];
|
||||||
|
|
||||||
assert_eq!([2, 3, 4], nice_slice)
|
assert_eq!([2, 3, 4], nice_slice)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let cat = ("Furry McFurson", 3.5);
|
let cat = ("Furry McFurson", 3.5);
|
||||||
let /* your pattern here */ = cat;
|
let (name, age) = cat;
|
||||||
|
|
||||||
println!("{} is {} years old.", name, age);
|
println!("{} is {} years old.", name, age);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
fn indexing_tuple() {
|
fn indexing_tuple() {
|
||||||
let numbers = (1, 2, 3);
|
let numbers = (1, 2, 3);
|
||||||
// Replace below ??? with the tuple indexing syntax.
|
// Replace below ??? with the tuple indexing syntax.
|
||||||
let second = ???;
|
let second = numbers.1;
|
||||||
|
|
||||||
assert_eq!(2, second,
|
assert_eq!(2, second,
|
||||||
"This is not the 2nd number in the tuple!")
|
"This is not the 2nd number in the tuple!")
|
||||||
|
|||||||
@ -12,6 +12,14 @@
|
|||||||
// Put your function here!
|
// Put your function here!
|
||||||
// fn calculate_apple_price {
|
// fn calculate_apple_price {
|
||||||
|
|
||||||
|
fn calculate_apple_price(quantity: usize) -> usize {
|
||||||
|
if quantity <= 40 {
|
||||||
|
quantity * 2
|
||||||
|
} else {
|
||||||
|
quantity * 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Don't modify this function!
|
// Don't modify this function!
|
||||||
#[test]
|
#[test]
|
||||||
fn verify_test() {
|
fn verify_test() {
|
||||||
|
|||||||
@ -17,14 +17,14 @@ fn string(arg: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
???("blue");
|
string_slice("blue");
|
||||||
???("red".to_string());
|
string("red".to_string());
|
||||||
???(String::from("hi"));
|
string(String::from("hi"));
|
||||||
???("rust is fun!".to_owned());
|
string("rust is fun!".to_owned());
|
||||||
???("nice weather".into());
|
string("nice weather".into());
|
||||||
???(format!("Interpolation {}", "Station"));
|
string(format!("Interpolation {}", "Station"));
|
||||||
???(&String::from("abc")[0..1]);
|
string_slice(&String::from("abc")[0..1]);
|
||||||
???(" hello there ".trim());
|
string_slice(" hello there ".trim());
|
||||||
???("Happy Monday!".to_string().replace("Mon", "Tues"));
|
string("Happy Monday!".to_string().replace("Mon", "Tues"));
|
||||||
???("mY sHiFt KeY iS sTiCkY".to_lowercase());
|
string("mY sHiFt KeY iS sTiCkY".to_lowercase());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,12 +19,12 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn returns_twice_of_positive_numbers() {
|
fn returns_twice_of_positive_numbers() {
|
||||||
assert_eq!(times_two(4), ???);
|
assert_eq!(times_two(4), 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn returns_twice_of_negative_numbers() {
|
fn returns_twice_of_negative_numbers() {
|
||||||
// TODO replace unimplemented!() with an assert for `times_two(-4)`
|
// TODO replace unimplemented!() with an assert for `times_two(-4)`
|
||||||
unimplemented!()
|
assert_eq!(times_two(-4), -8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,11 @@
|
|||||||
// Write a macro that passes the quiz! No hints this time, you can do it!
|
// Write a macro that passes the quiz! No hints this time, you can do it!
|
||||||
|
|
||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
macro_rules! my_macro {
|
||||||
|
($val:expr) => {
|
||||||
|
format!("Hello {}", $val)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|||||||
@ -23,17 +23,19 @@
|
|||||||
#![forbid(unused_imports)] // Do not change this, (or the next) line.
|
#![forbid(unused_imports)] // Do not change this, (or the next) line.
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
use std::sync::Mutex;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let numbers: Vec<_> = (0..100u32).collect();
|
let numbers: Vec<_> = (0..100u32).collect();
|
||||||
let shared_numbers = // TODO
|
let shared_numbers = Arc::new(Mutex::new(numbers)); // TODO
|
||||||
let mut joinhandles = Vec::new();
|
let mut joinhandles = Vec::new();
|
||||||
|
|
||||||
for offset in 0..8 {
|
for offset in 0..8 {
|
||||||
let child_numbers = // TODO
|
let child_numbers = Arc::clone(&shared_numbers); // TODO
|
||||||
joinhandles.push(thread::spawn(move || {
|
joinhandles.push(thread::spawn(move || {
|
||||||
let mut i = offset;
|
let mut i = offset;
|
||||||
let mut sum = 0;
|
let mut sum = 0;
|
||||||
|
let child_numbers = child_numbers.lock().unwrap();
|
||||||
while i < child_numbers.len() {
|
while i < child_numbers.len() {
|
||||||
sum += child_numbers[i];
|
sum += child_numbers[i];
|
||||||
i += 8;
|
i += 8;
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
pub enum List {
|
pub enum List {
|
||||||
Cons(i32, List),
|
Cons(i32, Box<List>),
|
||||||
Nil,
|
Nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,11 +33,11 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_empty_list() -> List {
|
pub fn create_empty_list() -> List {
|
||||||
unimplemented!()
|
List::Nil
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_non_empty_list() -> List {
|
pub fn create_non_empty_list() -> List {
|
||||||
unimplemented!()
|
List::Cons(0, Box::new(List::Nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@ -13,12 +13,12 @@
|
|||||||
fn main () {
|
fn main () {
|
||||||
let my_fav_fruits = vec!["banana", "custard apple", "avocado", "peach", "raspberry"];
|
let my_fav_fruits = vec!["banana", "custard apple", "avocado", "peach", "raspberry"];
|
||||||
|
|
||||||
let mut my_iterable_fav_fruits = ???; // TODO: Step 1
|
let mut my_iterable_fav_fruits = my_fav_fruits.iter(); // TODO: Step 1
|
||||||
|
|
||||||
assert_eq!(my_iterable_fav_fruits.next(), Some(&"banana"));
|
assert_eq!(my_iterable_fav_fruits.next(), Some(&"banana"));
|
||||||
assert_eq!(my_iterable_fav_fruits.next(), ???); // TODO: Step 2
|
assert_eq!(my_iterable_fav_fruits.next(), Some(&"custard apple")); // TODO: Step 2
|
||||||
assert_eq!(my_iterable_fav_fruits.next(), Some(&"avocado"));
|
assert_eq!(my_iterable_fav_fruits.next(), Some(&"avocado"));
|
||||||
assert_eq!(my_iterable_fav_fruits.next(), ???); // TODO: Step 2.1
|
assert_eq!(my_iterable_fav_fruits.next(), Some(&"peach")); // TODO: Step 2.1
|
||||||
assert_eq!(my_iterable_fav_fruits.next(), Some(&"raspberry"));
|
assert_eq!(my_iterable_fav_fruits.next(), Some(&"raspberry"));
|
||||||
assert_eq!(my_iterable_fav_fruits.next(), ???); // TODO: Step 3
|
assert_eq!(my_iterable_fav_fruits.next(), None); // TODO: Step 3
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,7 +12,11 @@ pub fn capitalize_first(input: &str) -> String {
|
|||||||
let mut c = input.chars();
|
let mut c = input.chars();
|
||||||
match c.next() {
|
match c.next() {
|
||||||
None => String::new(),
|
None => String::new(),
|
||||||
Some(first) => ???,
|
Some(first) => {
|
||||||
|
let mut s = first.to_string().to_uppercase();
|
||||||
|
s.push_str(&input[1..]);
|
||||||
|
s
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,7 +25,11 @@ pub fn capitalize_first(input: &str) -> String {
|
|||||||
// Return a vector of strings.
|
// Return a vector of strings.
|
||||||
// ["hello", "world"] -> ["Hello", "World"]
|
// ["hello", "world"] -> ["Hello", "World"]
|
||||||
pub fn capitalize_words_vector(words: &[&str]) -> Vec<String> {
|
pub fn capitalize_words_vector(words: &[&str]) -> Vec<String> {
|
||||||
vec![]
|
let mut v = Vec::new();
|
||||||
|
for word in words {
|
||||||
|
v.push(capitalize_first(word));
|
||||||
|
}
|
||||||
|
v
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 3.
|
// Step 3.
|
||||||
@ -29,7 +37,8 @@ pub fn capitalize_words_vector(words: &[&str]) -> Vec<String> {
|
|||||||
// Return a single string.
|
// Return a single string.
|
||||||
// ["hello", " ", "world"] -> "Hello World"
|
// ["hello", " ", "world"] -> "Hello World"
|
||||||
pub fn capitalize_words_string(words: &[&str]) -> String {
|
pub fn capitalize_words_string(words: &[&str]) -> String {
|
||||||
String::new()
|
let v = capitalize_words_vector(words);
|
||||||
|
v.join("")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@ -22,20 +22,34 @@ pub struct NotDivisibleError {
|
|||||||
|
|
||||||
// Calculate `a` divided by `b` if `a` is evenly divisible by `b`.
|
// Calculate `a` divided by `b` if `a` is evenly divisible by `b`.
|
||||||
// Otherwise, return a suitable error.
|
// Otherwise, return a suitable error.
|
||||||
pub fn divide(a: i32, b: i32) -> Result<i32, DivisionError> {}
|
pub fn divide(a: i32, b: i32) -> Result<i32, DivisionError> {
|
||||||
|
if b == 0 {
|
||||||
|
Err(DivisionError::DivideByZero)
|
||||||
|
} else {
|
||||||
|
if a % b == 0 {
|
||||||
|
Ok(a / b)
|
||||||
|
} else {
|
||||||
|
Err(DivisionError::NotDivisible(
|
||||||
|
NotDivisibleError{dividend: a, divisor: b}
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Complete the function and return a value of the correct type so the test passes.
|
// Complete the function and return a value of the correct type so the test passes.
|
||||||
// Desired output: Ok([1, 11, 1426, 3])
|
// Desired output: Ok([1, 11, 1426, 3])
|
||||||
fn result_with_list() -> () {
|
fn result_with_list() -> Result<Vec<i32>, DivisionError> {
|
||||||
let numbers = vec![27, 297, 38502, 81];
|
let numbers = vec![27, 297, 38502, 81];
|
||||||
let division_results = numbers.into_iter().map(|n| divide(n, 27));
|
let division_results = numbers.into_iter().map(|n| divide(n, 27).unwrap()).collect();
|
||||||
|
Ok(division_results)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Complete the function and return a value of the correct type so the test passes.
|
// Complete the function and return a value of the correct type so the test passes.
|
||||||
// Desired output: [Ok(1), Ok(11), Ok(1426), Ok(3)]
|
// Desired output: [Ok(1), Ok(11), Ok(1426), Ok(3)]
|
||||||
fn list_of_results() -> () {
|
fn list_of_results() -> Vec<Result<i32, DivisionError>> {
|
||||||
let numbers = vec![27, 297, 38502, 81];
|
let numbers = vec![27, 297, 38502, 81];
|
||||||
let division_results = numbers.into_iter().map(|n| divide(n, 27));
|
let division_results = numbers.into_iter().map(|n| divide(n, 27)).collect();
|
||||||
|
division_results
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@ -12,6 +12,11 @@ pub fn factorial(num: u64) -> u64 {
|
|||||||
// For an extra challenge, don't use:
|
// For an extra challenge, don't use:
|
||||||
// - recursion
|
// - recursion
|
||||||
// Execute `rustlings hint iterators4` for hints.
|
// Execute `rustlings hint iterators4` for hints.
|
||||||
|
let mut res = 1;
|
||||||
|
for i in 1..num+1 {
|
||||||
|
res *= i;
|
||||||
|
}
|
||||||
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@ -34,6 +34,13 @@ fn count_for(map: &HashMap<String, Progress>, value: Progress) -> usize {
|
|||||||
fn count_iterator(map: &HashMap<String, Progress>, value: Progress) -> usize {
|
fn count_iterator(map: &HashMap<String, Progress>, value: Progress) -> usize {
|
||||||
// map is a hashmap with String keys and Progress values.
|
// map is a hashmap with String keys and Progress values.
|
||||||
// map = { "variables1": Complete, "from_str": None, ... }
|
// map = { "variables1": Complete, "from_str": None, ... }
|
||||||
|
let mut count = 0;
|
||||||
|
for (_, val) in map.iter() {
|
||||||
|
if val == &value {
|
||||||
|
count += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
count
|
||||||
}
|
}
|
||||||
|
|
||||||
fn count_collection_for(collection: &[HashMap<String, Progress>], value: Progress) -> usize {
|
fn count_collection_for(collection: &[HashMap<String, Progress>], value: Progress) -> usize {
|
||||||
@ -52,6 +59,15 @@ fn count_collection_iterator(collection: &[HashMap<String, Progress>], value: Pr
|
|||||||
// collection is a slice of hashmaps.
|
// collection is a slice of hashmaps.
|
||||||
// collection = [{ "variables1": Complete, "from_str": None, ... },
|
// collection = [{ "variables1": Complete, "from_str": None, ... },
|
||||||
// { "variables2": Complete, ... }, ... ]
|
// { "variables2": Complete, ... }, ... ]
|
||||||
|
let mut count = 0;
|
||||||
|
for map in collection.iter() {
|
||||||
|
for (_, val) in map.iter() {
|
||||||
|
if val == &value {
|
||||||
|
count += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
count
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@ -10,5 +10,5 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn current_favorite_color() -> String {
|
fn current_favorite_color() -> String {
|
||||||
"blue"
|
"blue".to_string()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let word = String::from("green"); // Try not changing this line :)
|
let word = String::from("green"); // Try not changing this line :)
|
||||||
if is_a_color_word(word) {
|
if is_a_color_word(&word[..]) {
|
||||||
println!("That is a color word I know!");
|
println!("That is a color word I know!");
|
||||||
} else {
|
} else {
|
||||||
println!("That is not a color word I know.");
|
println!("That is not a color word I know.");
|
||||||
|
|||||||
@ -3,11 +3,12 @@
|
|||||||
|
|
||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
struct ColorClassicStruct {
|
struct ColorClassicStruct<'a> {
|
||||||
// TODO: Something goes here
|
name: &'a str,
|
||||||
|
hex: &'a str
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ColorTupleStruct(/* TODO: Something goes here */);
|
struct ColorTupleStruct<'a>(&'a str, &'a str);
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct UnitStruct;
|
struct UnitStruct;
|
||||||
@ -19,7 +20,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn classic_c_structs() {
|
fn classic_c_structs() {
|
||||||
// TODO: Instantiate a classic c struct!
|
// TODO: Instantiate a classic c struct!
|
||||||
// let green =
|
let green = ColorClassicStruct { name: "green", hex: "#00FF00" };
|
||||||
|
|
||||||
assert_eq!(green.name, "green");
|
assert_eq!(green.name, "green");
|
||||||
assert_eq!(green.hex, "#00FF00");
|
assert_eq!(green.hex, "#00FF00");
|
||||||
@ -28,7 +29,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn tuple_structs() {
|
fn tuple_structs() {
|
||||||
// TODO: Instantiate a tuple struct!
|
// TODO: Instantiate a tuple struct!
|
||||||
// let green =
|
let green = ColorTupleStruct ( "green", "#00FF00" );
|
||||||
|
|
||||||
assert_eq!(green.0, "green");
|
assert_eq!(green.0, "green");
|
||||||
assert_eq!(green.1, "#00FF00");
|
assert_eq!(green.1, "#00FF00");
|
||||||
@ -36,8 +37,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unit_structs() {
|
fn unit_structs() {
|
||||||
// TODO: Instantiate a unit struct!
|
// TODO: Instantiate a unit struct
|
||||||
// let unit_struct =
|
let unit_struct = UnitStruct;
|
||||||
let message = format!("{:?}s are fun!", unit_struct);
|
let message = format!("{:?}s are fun!", unit_struct);
|
||||||
|
|
||||||
assert_eq!(message, "UnitStructs are fun!");
|
assert_eq!(message, "UnitStructs are fun!");
|
||||||
|
|||||||
@ -34,7 +34,15 @@ mod tests {
|
|||||||
fn your_order() {
|
fn your_order() {
|
||||||
let order_template = create_order_template();
|
let order_template = create_order_template();
|
||||||
// TODO: Create your own order using the update syntax and template above!
|
// TODO: Create your own order using the update syntax and template above!
|
||||||
// let your_order =
|
let your_order = Order {
|
||||||
|
name: String::from("Hacker in Rust"),
|
||||||
|
year: 2019,
|
||||||
|
made_by_phone: false,
|
||||||
|
made_by_mobile: false,
|
||||||
|
made_by_email: true,
|
||||||
|
item_number: 123,
|
||||||
|
count: 1,
|
||||||
|
};
|
||||||
assert_eq!(your_order.name, "Hacker in Rust");
|
assert_eq!(your_order.name, "Hacker in Rust");
|
||||||
assert_eq!(your_order.year, order_template.year);
|
assert_eq!(your_order.year, order_template.year);
|
||||||
assert_eq!(your_order.made_by_phone, order_template.made_by_phone);
|
assert_eq!(your_order.made_by_phone, order_template.made_by_phone);
|
||||||
|
|||||||
@ -17,6 +17,7 @@ impl Package {
|
|||||||
fn new(sender_country: String, recipient_country: String, weight_in_grams: i32) -> Package {
|
fn new(sender_country: String, recipient_country: String, weight_in_grams: i32) -> Package {
|
||||||
if weight_in_grams <= 0 {
|
if weight_in_grams <= 0 {
|
||||||
// Something goes here...
|
// Something goes here...
|
||||||
|
panic!("Weight of package is less than 0.");
|
||||||
} else {
|
} else {
|
||||||
return Package {
|
return Package {
|
||||||
sender_country,
|
sender_country,
|
||||||
@ -26,12 +27,12 @@ impl Package {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_international(&self) -> ??? {
|
fn is_international(&self) -> bool {
|
||||||
// Something goes here...
|
self.sender_country != self.recipient_country
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_fees(&self, cents_per_gram: i32) -> ??? {
|
fn get_fees(&self, cents_per_gram: i32) -> i32 {
|
||||||
// Something goes here...
|
self.weight_in_grams * cents_per_gram
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +74,7 @@ mod tests {
|
|||||||
let sender_country = String::from("Spain");
|
let sender_country = String::from("Spain");
|
||||||
let recipient_country = String::from("Spain");
|
let recipient_country = String::from("Spain");
|
||||||
|
|
||||||
let cents_per_gram = ???;
|
let cents_per_gram = 3;
|
||||||
|
|
||||||
let package = Package::new(sender_country, recipient_country, 1500);
|
let package = Package::new(sender_country, recipient_country, 1500);
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,6 @@
|
|||||||
mod tests {
|
mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn you_can_assert() {
|
fn you_can_assert() {
|
||||||
assert!();
|
assert!(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,6 +8,6 @@
|
|||||||
mod tests {
|
mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn you_can_assert_eq() {
|
fn you_can_assert_eq() {
|
||||||
assert_eq!();
|
assert_eq!(1, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,11 +16,11 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn is_true_when_even() {
|
fn is_true_when_even() {
|
||||||
assert!();
|
assert!(is_even(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn is_false_when_odd() {
|
fn is_false_when_odd() {
|
||||||
assert!();
|
assert!(!is_even(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::sync::Mutex;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
@ -17,15 +18,15 @@ struct JobStatus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let status = Arc::new(JobStatus { jobs_completed: 0 });
|
let status = Arc::new(Mutex::new( JobStatus { jobs_completed: 0 }));
|
||||||
let status_shared = status.clone();
|
let status_shared = status.clone();
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
for _ in 0..10 {
|
for _ in 0..10 {
|
||||||
thread::sleep(Duration::from_millis(250));
|
thread::sleep(Duration::from_millis(250));
|
||||||
status_shared.jobs_completed += 1;
|
status_shared.lock().unwrap().jobs_completed += 1;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
while status.jobs_completed < 10 {
|
while status.lock().unwrap().jobs_completed < 10 {
|
||||||
println!("waiting... ");
|
println!("waiting... ");
|
||||||
thread::sleep(Duration::from_millis(500));
|
thread::sleep(Duration::from_millis(500));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,6 +16,11 @@ trait AppendBar {
|
|||||||
|
|
||||||
impl AppendBar for String {
|
impl AppendBar for String {
|
||||||
//Add your code here
|
//Add your code here
|
||||||
|
fn append_bar(self) -> Self {
|
||||||
|
let mut s = self.clone();
|
||||||
|
s.push_str("Bar");
|
||||||
|
s
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|||||||
@ -17,6 +17,13 @@ trait AppendBar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Add your code here
|
//TODO: Add your code here
|
||||||
|
impl AppendBar for Vec<String> {
|
||||||
|
fn append_bar(self) -> Self {
|
||||||
|
let mut v = self.clone();
|
||||||
|
v.push("Bar".to_string());
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|||||||
@ -9,6 +9,6 @@
|
|||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
x = 5;
|
let x = 5;
|
||||||
println!("x has the value {}", x);
|
println!("x has the value {}", x);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x;
|
let x = 10;
|
||||||
if x == 10 {
|
if x == 10 {
|
||||||
println!("Ten!");
|
println!("Ten!");
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = 3;
|
let mut x = 3;
|
||||||
println!("Number {}", x);
|
println!("Number {}", x);
|
||||||
x = 5; // don't change this line
|
x = 5; // don't change this line
|
||||||
println!("Number {}", x);
|
println!("Number {}", x);
|
||||||
|
|||||||
@ -4,6 +4,6 @@
|
|||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x: i32;
|
let x: i32 = 10;
|
||||||
println!("Number {}", x);
|
println!("Number {}", x);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,6 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
let number = "T-H-R-E-E"; // don't change this line
|
let number = "T-H-R-E-E"; // don't change this line
|
||||||
println!("Spell a Number : {}", number);
|
println!("Spell a Number : {}", number);
|
||||||
number = 3;
|
let number = 3;
|
||||||
println!("Number plus two is : {}", number + 2);
|
println!("Number plus two is : {}", number + 2);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
const NUMBER = 3;
|
const NUMBER: i8 = 3;
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Number {}", NUMBER);
|
println!("Number {}", NUMBER);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user