cargo fmt

Standard Rust formatting practice
This commit is contained in:
rrokkam 2020-07-19 12:33:57 -07:00
parent fbe24e35b5
commit a699803ce7
3 changed files with 29 additions and 14 deletions

View File

@ -4,35 +4,39 @@ use std::vec;
pub struct Item { pub struct Item {
pub name: string::String, pub name: string::String,
pub sell_in: i32, pub sell_in: i32,
pub quality: i32 pub quality: i32,
} }
impl Item { impl Item {
pub fn new(name: String, sell_in: i32, quality: i32) -> Item { pub fn new(name: String, sell_in: i32, quality: i32) -> Item {
Item {name: name, sell_in: sell_in, quality: quality} Item {
name: name,
sell_in: sell_in,
quality: quality,
}
} }
} }
pub struct GildedRose { pub struct GildedRose {
pub items: vec::Vec<Item> pub items: vec::Vec<Item>,
} }
impl GildedRose { impl GildedRose {
pub fn new(items: vec::Vec<Item>) -> GildedRose { pub fn new(items: vec::Vec<Item>) -> GildedRose {
GildedRose {items: items} GildedRose { items: items }
} }
pub fn update_quality(&mut self) { pub fn update_quality(&mut self) {
for item in &mut self.items { for item in &mut self.items {
if item.name != "Aged Brie" && item.name != "Backstage passes to a TAFKAL80ETC concert" { if item.name != "Aged Brie" && item.name != "Backstage passes to a TAFKAL80ETC concert"
{
if item.quality > 0 { if item.quality > 0 {
if item.name != "Sulfuras, Hand of Ragnaros" { if item.name != "Sulfuras, Hand of Ragnaros" {
item.quality = item.quality - 1; item.quality = item.quality - 1;
} }
} }
} else { } else {
if item.quality < 50 if item.quality < 50 {
{
item.quality = item.quality + 1; item.quality = item.quality + 1;
if item.name == "Backstage passes to a TAFKAL80ETC concert" { if item.name == "Backstage passes to a TAFKAL80ETC concert" {

View File

@ -1,4 +1,4 @@
use super::{Item, GildedRose}; use super::{GildedRose, Item};
#[test] #[test]
pub fn foo() { pub fn foo() {

View File

@ -1,7 +1,6 @@
mod gildedrose; mod gildedrose;
use gildedrose::{Item, GildedRose}; use gildedrose::{GildedRose, Item};
fn main() { fn main() {
let items = vec![ let items = vec![
@ -10,11 +9,23 @@ fn main() {
Item::new(String::from("Elixir of the Mongoose"), 5, 7), Item::new(String::from("Elixir of the Mongoose"), 5, 7),
Item::new(String::from("Sulfuras, Hand of Ragnaros"), 0, 80), Item::new(String::from("Sulfuras, Hand of Ragnaros"), 0, 80),
Item::new(String::from("Sulfuras, Hand of Ragnaros"), -1, 80), Item::new(String::from("Sulfuras, Hand of Ragnaros"), -1, 80),
Item::new(String::from("Backstage passes to a TAFKAL80ETC concert"), 15, 20), Item::new(
Item::new(String::from("Backstage passes to a TAFKAL80ETC concert"), 10, 49), String::from("Backstage passes to a TAFKAL80ETC concert"),
Item::new(String::from("Backstage passes to a TAFKAL80ETC concert"), 5, 49), 15,
20,
),
Item::new(
String::from("Backstage passes to a TAFKAL80ETC concert"),
10,
49,
),
Item::new(
String::from("Backstage passes to a TAFKAL80ETC concert"),
5,
49,
),
// this conjured item does not work properly yet // this conjured item does not work properly yet
Item::new(String::from("Conjured Mana Cake"), 3, 6) Item::new(String::from("Conjured Mana Cake"), 3, 6),
]; ];
let mut rose = GildedRose::new(items); let mut rose = GildedRose::new(items);