The elves trudged into the North Pole office, their little faces as frosty as leftover cocoa. The holiday crunch was bad enough, but Blitzen’s latest antics had turned it into a nightmare. As the self-appointed “Tech Lead,” Blitzen wouldn’t stop yapping about optimizing Rust code that didn’t need optimizing. Meanwhile, the real issues in Santa’s repo—the gift filtering bug and the broken nice-kid calculator—were piling up like unwrapped presents on December 24th.
The elves slumped into their desks, morale at absolute zero. That’s when Santa stomped into the room, red-faced and gripping his enormous candy cane staff. His expression said it all: Unhinged Santa Mode Activated.
“WHAT IN THE NAME OF PRANCER’S LEFT HOOF IS GOING ON HERE?!” Santa bellowed. “Blitzen, what’s this I hear about you trying to write your own grep?!”
Blitzen froze, mid-boast about his hand-rolled, regex-powered masterpiece. “Uh, well, I thought—”
“You thought? You thought I needed a worse grep when the sleigh’s landing system is malfunctioning?!” Santa’s eyes blazed like LEDs on overclock. “Do you know where we landed yesterday?! Florida. FLORIDA, BLITZEN! You ever tried explaining a snow-laden sleigh to a guy in flip-flops?!”
Santa turned to the rest of the elves. “Everyone, listen up. Blitzen... you’re FIRED!”
The room gasped. Even the code compiler on the corner workstation seemed to pause in shock. Blitzen’s antlers drooped.
“Well, not fired,” Santa clarified, stroking his beard. “But you’re off tech lead. Effective immediately, you’re on…” he smirked, “Candy Cane API maintenance. Enjoy your new repo.”
The elves stifled giggles as Blitzen sulked away. Santa clapped his hands, bringing their attention back to the matter at hand.
“Now, here’s the real problem, folks. The sleigh’s landing system needs snow data, but look at what I got instead.” He waved a crinkled printout. “Snow weights! In kilograms and pounds! I don’t know what any of this means! What I need is actionable snow data—converted into snowballs.”
The elves exchanged worried glances.
“I want you to implement the From<T>
trait to convert these.” Santa jabbed at the paper. “We’ve got SnowKg(pub f32)
and SnowLb(pub f32)
, but I need them in a usable format: Snowball(pub i64)
! And make it snappy! Christmas Eve doesn’t debug itself!”
The room buzzed with renewed energy. The elves, though still peeved at Blitzen, couldn’t help but feel the spark of a good challenge. Snowball-ready data? Time to roll up their sleeves—and their structs.
Santa grinned as he marched out. “And if anyone so much as mentions rewriting ls
in Rust, you’re on tinsel-wrapping duty.”
From<T>
trait for the SnowKg
and SnowLb
types to convert them into Snowball
type.Snowball
type should contain the number of snowballs that can be made from the given weight.SNOWBALL_WEIGHT_KG
and SNOWBALL_WEIGHT_LB
constants to calculate the number of snowballs.If you’re stuck or need a starting point, here are some hints to help you along the way!
Use the SNOWBALL_WEIGHT_KG
and SNOWBALL_WEIGHT_LB
constants to find the number of snowballs from a weight.
Implement the From<T>
trait for each type. e.g. impl From<WeightInKg> for Snowball
.
Inside the impl From<T> for Snowball
block, calculate the number of snowballs from the input type. e.g.
fn from(weight: SnowKg) -> Self {
let value = "calculate the number of snowballs from weight";
SnowBall(value)
}
Use round()
to round the result to the nearest whole number. e.g. value.round()
.
Convert the result to an integer using as i64
.
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(value: SnowKg) -> Self { let snowballs = value.0 / SNOWBALL_WEIGHT_KG; Snowball::new(snowballs.round() as i64) }}impl From<SnowLb> for Snowball { fn from(value: SnowLb) -> Self { let snowballs = value.0 / SNOWBALL_WEIGHT_LB; Snowball::new(snowballs.round() as i64) }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { fn from(snow_kg: SnowKg) -> Snowball { let num: i64 = ( snow_kg.0 / SNOWBALL_WEIGHT_KG).round() as i64; Snowball::new(num) }}impl From<SnowLb> for Snowball { fn from(snow_lb: SnowLb) -> Snowball { let num: i64 = (snow_lb.0 / SNOWBALL_WEIGHT_LB).round() as i64; Snowball::new(num) }}// 2. Implement the same for SnowLb
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(snow_kg: SnowKg) -> Self { let snowballs = (snow_kg.0 / SNOWBALL_WEIGHT_KG).round() as i64; Snowball(snowballs) }}// 2. Implement the same for SnowLbimpl From<SnowLb> for Snowball { fn from(snow_lb: SnowLb) -> Self { let snowballs = (snow_lb.0 / SNOWBALL_WEIGHT_LB).round() as i64; Snowball(snowballs) }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(weight: SnowKg) -> Self { let weight = weight.0; let value = weight / SNOWBALL_WEIGHT_KG; Self::new(value.round() as i64) }}// 2. Implement the same for SnowLbimpl From<SnowLb> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(weight: SnowLb) -> Self { let weight = weight.0; let value = weight / SNOWBALL_WEIGHT_LB; Self::new(value.round() as i64) }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(weight: SnowKg) -> Self { Self((weight.0 / SNOWBALL_WEIGHT_KG).round() as i64) }}// 2. Implement the same for SnowLbimpl From<SnowLb> for Snowball { fn from(weight: SnowLb) -> Self { Self((weight.0 / SNOWBALL_WEIGHT_LB).round() as i64) }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(other: SnowKg) -> Self { Self((other.0 / SNOWBALL_WEIGHT_KG).round() as i64) }}// 2. Implement the same for SnowLbimpl From<SnowLb> for Snowball { fn from(other: SnowLb) -> Self { Self((other.0 / SNOWBALL_WEIGHT_LB).round() as i64) }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { fn from(weight: SnowKg) -> Snowball { let balls = (weight.0 / SNOWBALL_WEIGHT_KG).round() as i64; Snowball::new(balls) }}impl From<SnowLb> for Snowball { fn from(weight: SnowLb) -> Snowball { let balls = (weight.0 / SNOWBALL_WEIGHT_LB).round() as i64; Snowball::new(balls) }}// 2. Implement the same for SnowLb
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(value: SnowKg) -> Self { Self((value.0 / SNOWBALL_WEIGHT_KG).round() as i64) }}impl From<SnowLb> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(value: SnowLb) -> Self { Self((value.0 / SNOWBALL_WEIGHT_LB).round() as i64) }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(weight: SnowKg) -> Self { let value = weight.0 / SNOWBALL_WEIGHT_KG; Snowball(value.round() as i64) }}// 2. Implement the same for SnowLb impl From<SnowKg> for Snowball {impl From<SnowLb> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(weight: SnowLb) -> Self { let value = weight.0 / SNOWBALL_WEIGHT_LB; Snowball(value.round() as i64) }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(weight: SnowKg) -> Self { let value = (weight.0 / SNOWBALL_WEIGHT_KG).round() as i64; Snowball(value) }}// 2. Implement the same for SnowLbimpl From<SnowLb> for Snowball { fn from(weight: SnowLb) -> Self { let value = (weight.0 / SNOWBALL_WEIGHT_LB).round() as i64; Snowball(value) }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(snow_kg: SnowKg) -> Self { Snowball((snow_kg.0 / SNOWBALL_WEIGHT_KG).round() as i64) }}// 2. Implement the same for SnowLbimpl From<SnowLb> for Snowball { fn from(snow_lb: SnowLb) -> Self { Snowball((snow_lb.0 / SNOWBALL_WEIGHT_LB).round() as i64) }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { fn from(kg: SnowKg) -> Self { Self((kg.0 / SNOWBALL_WEIGHT_KG).round() as i64) }}impl From<SnowLb> for Snowball { fn from(lb: SnowLb) -> Self { Self((lb.0 / SNOWBALL_WEIGHT_LB).round() as i64) }}// 2. Implement the same for SnowLb
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { fn from(kg: SnowKg) -> Self { Self::new((kg.0 / SNOWBALL_WEIGHT_KG).round() as i64) }}impl From<SnowLb> for Snowball { fn from(lb: SnowLb) -> Self { Self::new((lb.0 / SNOWBALL_WEIGHT_LB).round() as i64) }}// 2. Implement the same for SnowLb
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(weight: SnowKg) -> Self { let value = weight.0 / SNOWBALL_WEIGHT_KG ; Snowball(value.round() as i64) }}// 2. Implement the same for SnowLbimpl From<SnowLb> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(weight: SnowLb) -> Self { let value = weight.0 / SNOWBALL_WEIGHT_LB; Snowball(value.round() as i64) }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { fn from(value: SnowKg) -> Snowball { Snowball((value.0 / SNOWBALL_WEIGHT_KG).round() as i64) }}impl From<SnowLb> for Snowball { fn from(value: SnowLb) -> Snowball { Snowball((value.0 / SNOWBALL_WEIGHT_LB).round() as i64) }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(value: SnowKg) -> Self { let SnowKg(x) = value; Snowball::new((x / SNOWBALL_WEIGHT_KG).round() as i64) }}impl From<SnowLb> for Snowball { fn from(value: SnowLb) -> Self { let SnowLb(x) = value; Snowball::new((x / SNOWBALL_WEIGHT_LB).round() as i64) }}// 2. Implement the same for SnowLb
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(kg: SnowKg) -> Snowball { let snNumRaw = kg.0 / SNOWBALL_WEIGHT_KG + 0.5; let snNum: i64 = snNumRaw as i64; Snowball::new(snNum) }}impl From<SnowLb> for Snowball { fn from(lb: SnowLb) -> Snowball { let snNumRaw = lb.0 / SNOWBALL_WEIGHT_LB + 0.5; let snNum: i64 = snNumRaw as i64; Snowball::new(snNum) }}// 2. Implement the same for SnowLb
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(kg: SnowKg) -> Self { let n = kg.0 / SNOWBALL_WEIGHT_KG; return Snowball(n.round() as i64); }}// 2. Implement the same for SnowLbimpl From<SnowLb> for Snowball { fn from(lb: SnowLb) -> Self { let n = lb.0 / SNOWBALL_WEIGHT_LB; return Snowball(n.round() as i64); }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg (pub f64);impl SnowKg { pub fn new (kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb (pub f64);impl SnowLb { pub fn new (lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball (pub i64);impl Snowball { pub fn new (snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { fn from (input: SnowKg) -> Self { Snowball((input.0 / SNOWBALL_WEIGHT_KG).round() as i64) }}impl From<SnowLb> for Snowball { fn from (input: SnowLb) -> Self { Snowball((input.0 / SNOWBALL_WEIGHT_LB).round() as i64) }}// 2. Implement the same for SnowLb
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { fn from(kg: SnowKg) -> Snowball { Snowball((kg.0 / SNOWBALL_WEIGHT_KG).round() as i64) }}impl From<SnowLb> for Snowball { fn from(lb: SnowLb) -> Snowball { Snowball((lb.0 / SNOWBALL_WEIGHT_LB).round() as i64) }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { fn from(value: SnowKg) -> Self { let snow_kg = value.0; let snowball = (snow_kg / SNOWBALL_WEIGHT_KG).round() as i64; Snowball(snowball as i64) } // 1. Implement the conversion from SnowKg to Snowball}impl From<SnowLb> for Snowball { fn from(value: SnowLb) -> Self { let snow_lb = value.0; let snowball = (snow_lb / SNOWBALL_WEIGHT_LB).round() as i64; Snowball(snowball) }}// 2. Implement the same for SnowLb
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}// 1. Implement the conversion from SnowKg to Snowballimpl From<SnowKg> for Snowball { fn from(weight: SnowKg) -> Self { let value = (weight.0 / SNOWBALL_WEIGHT_KG).round(); Snowball(value as i64) }}// 2. Implement the same for SnowLbimpl From<SnowLb> for Snowball { fn from(weight: SnowLb) -> Self { let value = (weight.0 / SNOWBALL_WEIGHT_LB).round(); Snowball(value as i64) }}
use std::ops::Mul;const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(value: SnowKg) -> Self { Self((value.0 / SNOWBALL_WEIGHT_KG).round() as i64) }}// 2. Implement the same for SnowLbimpl From<SnowLb> for Snowball { fn from(value: SnowLb) -> Self { Self((value.0 / SNOWBALL_WEIGHT_LB).round() as i64) }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(skg: SnowKg) -> Self { Self::new((skg.0 / SNOWBALL_WEIGHT_KG).round() as i64) }}// 2. Implement the same for SnowLbimpl From<SnowLb> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(slb: SnowLb) -> Self { Self::new((slb.0 / SNOWBALL_WEIGHT_LB).round() as i64) }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(value: SnowKg) -> Self { let value = (value.0 / SNOWBALL_WEIGHT_KG).round(); Self(value as i64) }}impl From<SnowLb> for Snowball { // 2. Implement the conversion from SnowLb to Snowball fn from(value: SnowLb) -> Self { let value = (value.0 / SNOWBALL_WEIGHT_LB).round(); Self(value as i64) }}// 2. Implement the same for SnowLb
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { fn from(value: SnowKg) -> Self { Snowball::new((value.0 / SNOWBALL_WEIGHT_KG).round() as i64) }}impl From<SnowLb> for Snowball { fn from(value: SnowLb) -> Self { Snowball::new((value.0 / SNOWBALL_WEIGHT_LB).round() as i64) }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { fn from(snow: SnowKg) -> Self { Snowball((snow.0 / SNOWBALL_WEIGHT_KG).round() as i64) }}impl From<SnowLb> for Snowball { fn from(snow: SnowLb) -> Self { Snowball((snow.0 / SNOWBALL_WEIGHT_LB).round() as i64) }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { fn from(value: SnowKg) -> Self { Snowball(f64::round(value.0 / SNOWBALL_WEIGHT_KG) as i64) }}impl From<SnowLb> for Snowball { fn from(value: SnowLb) -> Self { Snowball(f64::round(value.0 / SNOWBALL_WEIGHT_LB) as i64) }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(weight: SnowKg) -> Self { let value = (weight.0 / SNOWBALL_WEIGHT_KG).round(); Self::new(value as i64) }}impl From<SnowLb> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(weight: SnowLb) -> Self { let value = (weight.0 / SNOWBALL_WEIGHT_LB).round(); Self::new(value as i64) }}// 2. Implement the same for SnowLb
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(weight: SnowKg) -> Self { let value = (weight.0 / SNOWBALL_WEIGHT_KG).round(); Self::new(value as i64) }}impl From<SnowLb> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(weight: SnowLb) -> Self { let value = (weight.0 / SNOWBALL_WEIGHT_LB).round(); Self::new(value as i64) }}// 2. Implement the same for SnowLb
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { fn from(value: SnowKg) -> Self { Snowball((value.0 / SNOWBALL_WEIGHT_KG).round() as i64) }}impl From<SnowLb> for Snowball { fn from(value: SnowLb) -> Self { Snowball((value.0 / SNOWBALL_WEIGHT_LB).round() as i64) }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(weight: SnowKg) -> Self { let value = (weight.0 / SNOWBALL_WEIGHT_KG).round(); Snowball(value as i64) }}// 2. Implement the same for SnowLbimpl From<SnowLb> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(weight: SnowLb) -> Self { let value = (weight.0 / SNOWBALL_WEIGHT_LB).round(); Snowball(value as i64) }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(kg: SnowKg) -> Self { Snowball::new((kg.0 / SNOWBALL_WEIGHT_KG).round() as i64) }}// 2. Implement the same for SnowLbimpl From<SnowLb> for Snowball { fn from(lb: SnowLb) -> Self { Snowball::new((lb.0 / SNOWBALL_WEIGHT_LB).round() as i64) }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(kg: SnowKg) -> Self { match kg { SnowKg(kg) => Snowball::new((kg / SNOWBALL_WEIGHT_KG).round() as i64) } }}// 2. Implement the same for SnowLbimpl From<SnowLb> for Snowball { fn from(lb: SnowLb) -> Self { match lb { SnowLb(lb) => Snowball::new((lb / SNOWBALL_WEIGHT_LB).round() as i64) } }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { fn from(other: SnowKg) -> Self { Snowball((other.0 / SNOWBALL_WEIGHT_KG).round() as i64) }}impl From<SnowLb> for Snowball { fn from(other: SnowLb) -> Self { Snowball((other.0 / SNOWBALL_WEIGHT_LB).round() as i64) }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(snow_kg: SnowKg) -> Self { Snowball::new((snow_kg.0 / SNOWBALL_WEIGHT_KG).round() as i64) }}impl From<SnowLb> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(snow_lb: SnowLb) -> Self { Snowball::new((snow_lb.0 / SNOWBALL_WEIGHT_LB).round() as i64) }}// 2. Implement the same for SnowLb
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(snow_kg: SnowKg) -> Snowball { Self((snow_kg.0 / SNOWBALL_WEIGHT_KG).round() as i64) }}impl From<SnowLb> for Snowball { // 2. Implement the same for SnowLb fn from(snow_lb: SnowLb) -> Snowball { Self((snow_lb.0 / SNOWBALL_WEIGHT_LB).round() as i64) }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { fn from(value: SnowKg) -> Self { Self((value.0 / SNOWBALL_WEIGHT_KG).round() as i64) }}impl From<SnowLb> for Snowball { fn from(value: SnowLb) -> Self { Self((value.0 / SNOWBALL_WEIGHT_LB).round() as i64) }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { fn from(value: SnowKg) -> Self { Self((value.0 / SNOWBALL_WEIGHT_KG).round() as i64) }}impl From<SnowLb> for Snowball { fn from(value: SnowLb) -> Self { Self((value.0 / SNOWBALL_WEIGHT_LB).round() as i64) }}// 2. Implement the same for SnowLb
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(weight: SnowKg) -> Self { let value = weight.0 / SNOWBALL_WEIGHT_KG; Self::new(value.round() as i64) }}// 2. Implement the same for SnowLbimpl From<SnowLb> for Snowball { fn from(lb: SnowLb) -> Self { let value = lb.0 / SNOWBALL_WEIGHT_LB; Self::new(value.round() as i64) }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(weight: SnowKg) -> Self { let value = weight.0 / SNOWBALL_WEIGHT_KG; Self::new(value.round() as i64) }}// 2. Implement the same for SnowLbimpl From<SnowLb> for Snowball { // 1. Implement the conversion from SnowLb to Snowball fn from(weight: SnowLb) -> Self { let value = weight.0 / SNOWBALL_WEIGHT_LB; Self::new(value.round() as i64) }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(snow_kg: SnowKg) -> Snowball { Snowball((snow_kg.0 / SNOWBALL_WEIGHT_KG).round() as i64) }}// 2. Implement the same for SnowLbimpl From<SnowLb> for Snowball { fn from(snow_lb: SnowLb) -> Snowball { Snowball((snow_lb.0 / SNOWBALL_WEIGHT_LB).round() as i64) }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { fn from(x: SnowKg) -> Self { Snowball((x.0 / SNOWBALL_WEIGHT_KG).round() as i64) }}impl From<SnowLb> for Snowball { fn from(x: SnowLb) -> Self { Snowball((x.0 / SNOWBALL_WEIGHT_LB).round() as i64) }}// 2. Implement the same for SnowLb
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(value: SnowKg) -> Self { let snowballs = (value.0 / SNOWBALL_WEIGHT_KG).round() as i64; Snowball(snowballs) }}impl From<SnowLb> for Snowball { // 2. Implement the conversion from SnowLb to Snowball fn from(value: SnowLb) -> Self { let snowballs = (value.0 / SNOWBALL_WEIGHT_LB).round() as i64; Snowball(snowballs) }}// 2. Implement the same for SnowLb
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { fn from(weight: SnowKg) -> Snowball { let sw = (weight.0 / SNOWBALL_WEIGHT_KG).round() as i64; return Snowball::new(sw); }}impl From<SnowLb> for Snowball { fn from(weight: SnowLb) -> Snowball { let sw = (weight.0 / SNOWBALL_WEIGHT_LB).round() as i64; return Snowball::new(sw); }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(weight: SnowKg) -> Self { Self::new((weight.0 / SNOWBALL_WEIGHT_KG).round() as i64) }}// 2. Implement the same for SnowLbimpl From<SnowLb> for Snowball { fn from(weight: SnowLb) -> Self { Self::new((weight.0 / SNOWBALL_WEIGHT_LB).round() as i64) }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(weight: SnowKg) -> Self { Self::new((weight.0 / SNOWBALL_WEIGHT_KG).round() as i64) }}// 2. Implement the same for SnowLbimpl From<SnowLb> for Snowball { fn from(weight: SnowLb) -> Self { Self::new((weight.0 / SNOWBALL_WEIGHT_LB).round() as i64) }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(weight: SnowKg) -> Self { let num_snowballs = (weight.0 / SNOWBALL_WEIGHT_KG).round() as i64; Snowball(num_snowballs) }}// 2. Implement the same for SnowLbimpl From<SnowLb> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(weight: SnowLb) -> Self { let num_snowballs = (weight.0 / SNOWBALL_WEIGHT_LB).round() as i64; Snowball(num_snowballs) }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(value: SnowKg) -> Self { Snowball::new((value.0 / SNOWBALL_WEIGHT_KG).round() as i64) }}impl From<SnowLb> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(value: SnowLb) -> Self { Snowball::new((value.0 / SNOWBALL_WEIGHT_LB).round() as i64) }}
const SNOWBALL_WEIGHT_KG: f64 = 0.2;const SNOWBALL_WEIGHT_LB: f64 = 0.441;pub struct SnowKg(pub f64);impl SnowKg { pub fn new(kg: f64) -> Self { SnowKg(kg) }}pub struct SnowLb(pub f64);impl SnowLb { pub fn new(lb: f64) -> Self { SnowLb(lb) }}pub struct Snowball(pub i64);impl Snowball { pub fn new(snowballs: i64) -> Self { Snowball(snowballs) }}impl From<SnowKg> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(weight: SnowKg) -> Self { let value = (weight.0 / SNOWBALL_WEIGHT_KG).round() as i64; Snowball(value) }}impl From<SnowLb> for Snowball { // 1. Implement the conversion from SnowKg to Snowball fn from(weight: SnowLb) -> Self { let value = (weight.0 / SNOWBALL_WEIGHT_LB).round() as i64; Snowball(value) }}// 2. Implement the same for SnowLb