Santa burst into the dev lounge, chugging his third espresso. "Great job yesterday, nerds! The is_nice
function? Chef's kiss. But now, I want structure. STRUCTURE! We’re going full-on Rustacean. I need a Kid
struct—immediately!"
The elves nodded enthusiastically, their tiny laptops open, running Arch Linux with bspwm because, obviously, they were that kind of devs. One elf, started yapping, "But Santa, why a struct? Isn’t this just overengineered?"
Santa slammed the table, shaking an untouched tray of gluten-free cookies. "No! A struct means no more random strings floating around. We need to encapsulate a kid's data—name, and niceness score. Plus, we’ll need some methods to make sense of it all."
The dev elves scrambled to work. In no time, they sketched out the basic blueprint. Santa glanced at the screen. "Not bad. But I will need this extended later. Keep it modular, bros!"
The room fell silent as the elves realized the implications. This was just the beginning of Santa’s unhinged data modeling spree.
The elves need your help to finish the Kid
struct.
Here is what you need to do:
Niceness
enum: Nice
and Naughty
. Nice
takes the number of good deeds.Kid
struct: name
of type String
and niceness
of type Niceness
.is_nice
function we created on Day 3 to an associated function of the Kid
struct.new()
associated function for the Kid
struct.If you're stuck, here are some hints to help you get back on track:
Nice(u32)
to represent the number of good deeds.field_name: field_type
, e.g., name: String
.impl
block without the self
parameter.::
instead of .
, e.g. Kid::is_nice(10, 1);
Self::is_nice
or Kid::is_nice
to call the associated function from within the impl
block.tdoan
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty,}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness,}// Move yesterday's function to an associated function in the structimpl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { // Return a Kid instance let niceness = if Self::is_nice(good_deeds, bad_deeds) { Niceness::Nice(good_deeds) } else { Niceness::Naughty }; Kid { name, niceness, } } pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75}}
jgpaiva
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness,}impl Kid{ // Move yesterday's function to an associated function in the struct pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75 }}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { let is_nice = Kid::is_nice(good_deeds, bad_deeds); Kid{ name, niceness: if is_nice { Niceness::Nice(good_deeds) } else { Niceness::Naughty } } }}
pwhenryuk
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { Naughty, Nice(u32)}pub struct Kid { pub name: String, pub niceness: Niceness}impl Kid { pub fn new(name:String, good_deeds: u32, bad_deeds: u32) -> Kid { if Self::is_nice(good_deeds, bad_deeds) { Kid { name, niceness: Niceness::Nice(good_deeds) } } else { Kid { name, niceness: Niceness::Naughty } } } pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); if ratio >= 0.75 { return true; } else { return false; } }}
henopied
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness}// Move yesterday's function to an associated function in the structpub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { let niceness = if is_nice(good_deeds, bad_deeds) { Niceness::Nice(good_deeds) } else { Niceness::Naughty }; Kid {name: name, niceness: niceness} }}
mei28
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { // Return a Kid instance Kid { name, niceness : if Kid::is_nice(good_deeds,bad_deeds) {Niceness::Nice(good_deeds)}else{Niceness::Naughty} } }// Move yesterday's function to an associated function in the structpub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75}}
kapaseker
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32),Naughty}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name:String, pub niceness: Niceness,}impl Kid { // Move yesterday's function to an associated function in the struct pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75 }}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { let niceness = if Kid::is_nice(good_deeds, bad_deeds) { Niceness::Nice(good_deeds) } else { Niceness::Naughty }; Kid { name, niceness } }}
hagl
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { Nice(u32), Naughty}pub struct Kid { pub name: String, pub niceness: Niceness}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { Kid { name, niceness: if Kid::is_nice(good_deeds, bad_deeds) { Niceness::Nice(good_deeds) } else { Niceness::Naughty } } } pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75 }}
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Naughty, Nice(u32),}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness,}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Self{ if Self::is_nice(good_deeds, bad_deeds) { Self { name: name, niceness: Niceness::Nice(good_deeds) } } else { Self { name: name, niceness: Niceness::Naughty } } } pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75 }}
Pumkko
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty,}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness,}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { let niceness = if Self::is_nice(good_deeds, bad_deeds) { Niceness::Nice(good_deeds) } else { Niceness::Naughty }; Kid { name, niceness } } // Move yesterday's function to an associated function in the struct pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75 }}
mliertzer
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty,}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness,}impl Kid { fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75} pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { if Kid::is_nice(good_deeds, bad_deeds) { Kid{ name: name, niceness: Niceness::Nice(good_deeds) } } else { Kid{ name: name, niceness: Niceness::Naughty } } }}
doroshtapgh
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { // Return a Kid instance Kid { name, niceness: if Kid::is_nice(good_deeds, bad_deeds) { Niceness::Nice(good_deeds) } else { Niceness::Naughty } } } pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75 }}
chokkoyamada
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty,}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness,}// Move yesterday's function to an associated function in the structpub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { // Return a Kid instance let niceness = if is_nice(good_deeds, bad_deeds) { Niceness::Nice(good_deeds) } else { Niceness::Naughty }; Kid { name, niceness } }}
klllr
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice (u32), Naughty}pub struct Kid { pub name: String, pub niceness: Niceness // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public}// Move yesterday's function to an associated function in the structpub fn is_nice (good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75}impl Kid { pub fn new (name: String, good_deeds: u32, bad_deeds: u32) -> Kid { Self { name, niceness: match is_nice(good_deeds, bad_deeds) { true => Niceness::Nice(good_deeds), false => Niceness::Naughty } } }}
pilotso11
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Naughty, Nice(i32),}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness,}impl Kid { // Move yesterday's function to an associated function in the struct fn is_nice(good_deeds: u32, bad_deeds: u32) -> Niceness { if good_deeds == 0 && bad_deeds == 0 { return Niceness::Naughty; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); if ratio >= 0.75 { return Niceness::Nice(good_deeds as i32); } Niceness::Naughty } pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { // Return a Kid instance Kid { name, niceness: Kid::is_nice(good_deeds, bad_deeds) } }}
findgriffin
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness}// Move yesterday's function to an associated function in the structpub fn is_nice(good_deeds: u32, bad_deeds: u32) -> Niceness { if good_deeds == 0 && bad_deeds == 0 { return Niceness::Naughty; } let good = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good / (good + bad_deeds); if ratio >= 0.75 { return Niceness::Nice(good_deeds); } else { return Niceness::Naughty; }}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { // Return a Kid instance return Kid { name: name, niceness: is_nice(good_deeds, bad_deeds)} }}
habu1010
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty,}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness,}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { // Return a Kid instance let niceness = if Self::is_nice(good_deeds, bad_deeds) { Niceness::Nice(good_deeds) } else { Niceness::Naughty }; Kid { name, niceness, } } pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75 }}
mladen5000
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;/// The enum for niceness#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { Nice(u32), Naughty,}pub struct Kid { pub name: String, pub niceness: Niceness,}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { let niceness; if Self::is_nice(good_deeds, bad_deeds) { niceness = Niceness::Nice(good_deeds); } else { niceness = Niceness::Naughty; } Kid { name, niceness } } pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75 }}
rjensen
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness}// Move yesterday's function to an associated function in the structpub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { // Return a Kid instance let niceness = if is_nice(good_deeds, bad_deeds) { Niceness::Nice(good_deeds) } else { Niceness::Naughty }; Kid {name, niceness} }}
Ankit8848
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { Nice(u32), Naughty, // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds}pub struct Kid { pub name:String, pub niceness:Niceness, // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public}// Move yesterday's function to an associated function in the structimpl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { if Kid::is_nice(good_deeds, bad_deeds) { Self { name, niceness: Niceness::Nice(good_deeds), } } else { Self { name, niceness: Niceness::Naughty, } } } pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75 }}
Flash-Kaa
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { Nice(u32), Naughty}pub struct Kid { pub name: String, pub niceness: Niceness}// Move yesterday's function to an associated function in the structpub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Self { let niceness = if is_nice(good_deeds, bad_deeds) { Niceness::Nice(good_deeds) } else { Niceness::Naughty }; Kid {name, niceness} }}
oshunter124
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty,}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness}// Move yesterday's function to an associated function in the structpub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { // Return a Kid instance let niceness_bool = is_nice(good_deeds, bad_deeds); let niceness = if niceness_bool { Niceness::Nice(good_deeds) } else { Niceness::Naughty }; Kid { niceness, name } }}
rschmertz
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Naughty, Nice(u32)}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness}// Move yesterday's function to an associated function in the structpub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { // Return a Kid instance let nice_bool = is_nice(good_deeds, bad_deeds); let niceness = if nice_bool { Niceness::Nice(good_deeds) } else { Niceness::Naughty }; Kid { name, niceness } }}
rschmertz
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Naughty, Nice(u32)}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness}// Move yesterday's function to an associated function in the structpub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { // Return a Kid instance let nice_bool = is_nice(good_deeds, bad_deeds); let niceness = if nice_bool { Niceness::Nice(good_deeds) } else { Niceness::Naughty }; Kid { name, niceness } }}
json-stateham
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { let niceness = if Self::is_nice(good_deeds, bad_deeds) { Niceness::Nice(good_deeds) } else { Niceness::Naughty }; // Return a Kid instance Kid { name, niceness } } // Move yesterday's function to an associated function in the structpub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75}}
ankeetparikh
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness}impl Kid { pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75 } pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { // Return a Kid instance Kid { name: name, niceness: match Kid::is_nice(good_deeds, bad_deeds) { true => Niceness::Nice(good_deeds), false => Niceness::Naughty } } }}
eguefif
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty,}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness,}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { Kid { name, niceness: Kid::is_nice(good_deeds, bad_deeds) } } // Move yesterday's function to an associated function in the struct pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> Niceness { if good_deeds == 0 && bad_deeds == 0 { return Niceness::Naughty; } let good = good_deeds as f32 * GOOD_WEIGHT; let bad = bad_deeds as f32 * BAD_WEIGHT; let ratio = good / (good + bad); if ratio >= 0.75 { return Niceness::Nice(good_deeds) } Niceness::Naughty }}
MrDaves24
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty,}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness,}// Move yesterday's function to an associated function in the structimpl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { if Kid::is_nice(good_deeds, bad_deeds) { Self { name, niceness: Niceness::Nice(good_deeds), } } else { Self { name, niceness: Niceness::Naughty, } } } pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75 }}
Tarokc
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty,}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness,}// Move yesterday's function to an associated function in the structpub fn is_nice(good_deeds: u32, bad_deeds: u32) -> Niceness { if good_deeds == 0 && bad_deeds == 0 { return Niceness::Naughty; } let ratio = good_deeds as f32 * GOOD_WEIGHT/ (good_deeds as f32 * GOOD_WEIGHT + bad_deeds as f32 * BAD_WEIGHT); if ratio >= 0.75 { Niceness::Nice(good_deeds) } else { Niceness::Naughty }}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { // Return a Kid instance // Kid(name,is_nice(good_deeds,bad_deeds)) Kid {name:name, niceness:is_nice(good_deeds,bad_deeds)} }}
antenaina0
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness,}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { // Return a Kid instance let nice = Kid::is_nice(good_deeds, bad_deeds); let niceness = if nice { Niceness::Nice(good_deeds) } else { Niceness::Naughty }; Kid { name, niceness } } pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { let den = good_deeds + 2 * bad_deeds; if den == 0 { return false; } ((good_deeds as f32) / (den as f32)) >= 0.75 }}
tamanishi
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty,}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness,}// Move yesterday's function to an associated function in the structpub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { // Return a Kid instance if is_nice(good_deeds, bad_deeds) == true { Kid{name: name, niceness: Niceness::Nice(good_deeds)} } else { Kid{name: name, niceness: Niceness::Naughty} } }}
x0d12
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty,}pub struct Kid { pub name: String, // Add a field `name` of type `String` pub niceness: Niceness, // and `niceness` field of type `Niceness` // Make all fields public}impl Kid { // Move yesterday's function to an associated function in the struct pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75 } pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { // Return a Kid instance Kid { name, niceness: if Self::is_nice(good_deeds, bad_deeds) { Niceness::Nice(good_deeds) } else { Niceness::Naughty } } }}
aidan1magee
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { Nice(u32), Naughty, // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds}pub struct Kid { pub name: String, pub niceness: Niceness, // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public}// Move yesterday's function to an associated function in the structpub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { // Return a Kid instance match is_nice(good_deeds, bad_deeds) { true => Kid {name, niceness: Niceness::Nice(good_deeds)}, false => Kid {name, niceness: Niceness::Naughty} } }}
jobm
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty,}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness,}// Move yesterday's function to an associated function in the structpub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { // Return a Kid instance match is_nice(good_deeds, bad_deeds) { true => Kid {name, niceness: Niceness::Nice(good_deeds) }, false => Kid {name, niceness: Niceness::Naughty} } }}
hafihaf123
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty,}pub struct Kid { // Add a field `name` of type `String` pub name: String, // and `niceness` field of type `Niceness` pub niceness: Niceness, // Make all fields public}// Move yesterday's function to an associated function in the structimpl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { // Return a Kid instance let niceness = Kid::is_nice(good_deeds, bad_deeds); Kid { name, niceness, } } pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> Niceness { if good_deeds == 0 && bad_deeds == 0 { return Niceness::Naughty; } let good_weighted = good_deeds as f32 * GOOD_WEIGHT; let bad_weighted = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_weighted / (good_weighted + bad_weighted); if ratio >= 0.75 { Niceness::Nice(good_deeds) } else { Niceness::Naughty } }}
hafihaf123
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty,}pub struct Kid { // Add a field `name` of type `String` pub name: String, // and `niceness` field of type `Niceness` pub niceness: Niceness, // Make all fields public}// Move yesterday's function to an associated function in the structimpl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { // Return a Kid instance let niceness = Kid::is_nice(good_deeds, bad_deeds); Kid { name, niceness, } } pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> Niceness { if good_deeds == 0 && bad_deeds == 0 { return Niceness::Naughty; } let good_weighted = good_deeds as f32 * GOOD_WEIGHT; let bad_weighted = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_weighted / (good_weighted + bad_weighted); if ratio >= 0.75 { Niceness::Nice(good_deeds) } else { Niceness::Naughty } }}
rirze
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty,}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness,}impl Kid {// Move yesterday's function to an associated function in the structpub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> Niceness { let ratio = good_deeds as f32 * GOOD_WEIGHT / (good_deeds as f32 *GOOD_WEIGHT + BAD_WEIGHT*bad_deeds as f32); if ratio >= 0.75 { Niceness::Nice(good_deeds) } else { Niceness::Naughty }}}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { Kid { name: name, niceness: Kid::is_nice(good_deeds, bad_deeds) } }}
KLcpb
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty,}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness,}// Move yesterday's function to an associated function in the structimpl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { // Return a Kid instance Kid { name:name, niceness: match Self::is_nice(good_deeds,bad_deeds){true=>Niceness::Nice(good_deeds), false=>Niceness::Naughty} } } fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75}}
franlopezm
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty,}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness,}// Move yesterday's function to an associated function in the structpub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75}impl Kid { pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> Niceness { if is_nice(good_deeds, bad_deeds) { Niceness::Nice(good_deeds) } else { Niceness::Naughty } } pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { Self { name, niceness: Self::is_nice(good_deeds, bad_deeds) } }}
franlopezm
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty,}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness,}// Move yesterday's function to an associated function in the structpub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { let niceness = if is_nice(good_deeds, bad_deeds) { Niceness::Nice(good_deeds) } else { Niceness::Naughty }; Kid { name, niceness } }}
thenil3sh
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name : String, pub niceness : Niceness,}// Move yesterday's function to an associated function in the struct fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75 }impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { // Return a Kid instance Kid { name : String::from(name), niceness : if is_nice(good_deeds, bad_deeds){ Niceness::Nice(good_deeds) } else { Niceness::Naughty } } }}
arodrigue003
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness}impl Niceness { // Move yesterday's function to an associated function in the struct pub fn new(good_deeds: u32, bad_deeds: u32) -> Self { if good_deeds == 0 && bad_deeds == 0 { return Self::Naughty; } let good_deeds_f32 = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds_f32 / (good_deeds_f32 + bad_deeds); if ratio >= 0.75 { Self::Nice(good_deeds) } else { Self::Naughty } }}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { // Return a Kid instance Self { name, niceness: Niceness::new(good_deeds, bad_deeds) } }}
carlos-cardoso
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice (u32), Naughty,}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness,}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { // Return a Kid instance let niceness = if Kid::is_nice(good_deeds, bad_deeds){ Niceness::Nice(good_deeds) } else { Niceness::Naughty }; Kid{name, niceness} }// Move yesterday's function to an associated function in the structpub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75}}
terminox
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness}// Move yesterday's function to an associated function in the structpub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { // Return a Kid instance Kid { name: name, niceness: if is_nice(good_deeds, bad_deeds) { Niceness::Nice(good_deeds) } else { Niceness::Naughty } } }}
MCsamurai034
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty,}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness,}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { Kid { name, niceness: { if Self::is_nice(good_deeds, bad_deeds) { Niceness::Nice(good_deeds) } else { Niceness::Naughty } }, } } pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75 }}
rj-rmiyazaki
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), // 良い行いの数を保持する Naughty, // 特にデータを保持しない}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness,}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { // Return a Kid instance let is_nice = Self::is_nice(good_deeds,bad_deeds); let mut niceness:bool; // nicenessを直接初期化 let niceness = if is_nice { Niceness::Nice(good_deeds) } else { Niceness::Naughty }; // Kidインスタンスを返す Self { name, niceness } } // Move yesterday's function to an associated function in the struct fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75 }}
sarub0b0
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { Nice(u32), Naughty,}pub struct Kid { pub name: String, pub niceness: Niceness,}// Move yesterday's function to an associated function in the structpub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { let niceness = if is_nice(good_deeds, bad_deeds) { Niceness::Nice(good_deeds) } else { Niceness::Naughty }; Kid { name, niceness } }}
arilet
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty,}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness,}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { // Return a Kid instance Kid { name: name, niceness: match Kid::is_nice(good_deeds, bad_deeds) { true => Niceness::Nice(good_deeds), _ => Niceness::Naughty, } } } // Move yesterday's function to an associated function in the struct pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75 }}
tdtrung17693
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness}// Move yesterday's function to an associated function in the structpub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75 }impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { // Return a Kid instance let niceness = if is_nice(good_deeds, bad_deeds) { Niceness::Nice(good_deeds) } else { Niceness::Naughty }; return Kid { name: name, niceness: niceness, } }}
gmvar
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { Nice(u32), Naughty,}pub struct Kid { pub name: String, pub niceness: Niceness}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { let niceness = if Kid::is_nice(good_deeds, bad_deeds) { Niceness::Nice(good_deeds) } else { Niceness::Naughty }; // Return a Kid Kid { name, niceness } } pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75 }}
MaoX-Yu
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;#[derive(Debug, PartialEq)] // needed for testspub enum Niceness { // Create the enum variants `Nice` and `Naughty` // Variant `Nice` is a tuple struct that holds the number of good deeds Nice(u32), Naughty,}pub struct Kid { // Add a field `name` of type `String` // and `niceness` field of type `Niceness` // Make all fields public pub name: String, pub niceness: Niceness,}impl Kid { pub fn new(name: String, good_deeds: u32, bad_deeds: u32) -> Kid { // Return a Kid instance if Self::is_nice(good_deeds, bad_deeds) { return Self { name, niceness: Niceness::Nice(good_deeds), } } Self { name, niceness: Niceness::Naughty, } } // Move yesterday's function to an associated function in the struct pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32 * GOOD_WEIGHT; let bad_deeds = bad_deeds as f32 * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75 }}