Pure Programmer
Blue Matrix


Cluster Map

Project: Length Class

Write an immutable class to represent length. You will need to setup an enumeration for the different possible units of mm, cm, m, km, in, ft, yd, and mile. Pick one of the units for your internal representations and provide a private constructor that takes the length value and a unit enumeration. Then provide a static factory method that takes the same arguments and returns a length object. The factory method will store objects it creates in a map so that it can use the map to return previously cached objects that match. This helps to keep the number of objects created down. Provide toString type method that returns a reasonable representation of the length object(value plus nearest unit) in SI and one for English units.

Provide add and subtract methods that take a length object as an argument and returns the sum or difference of the calling object plus the argument object. Also provide multiply and divide methods that take a non-dimensional double argument and return a length object that is the product or quotient of the calling object and the non-dimensional double.

See See [[Unit_of_length|Unit of Length]]

Output
$ rustc LengthClass.rs error: expected identifier, found keyword `enum` --> LengthClass.rs:18:2 | 14 | struct Length { | ------ while parsing this struct ... 18 | enum Unit { | ^^^^ expected identifier, found keyword error: unknown format trait `f` --> LengthClass.rs:132:24 | 132 | return format!("{0:.3f} {1:s}", finalValue, finalUnit); | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error: unknown format trait `s` --> LengthClass.rs:132:30 | 132 | return format!("{0:.3f} {1:s}", finalValue, finalUnit); | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error: unknown format trait `s` --> LengthClass.rs:152:29 | 152 | println!("{}", format!("{0:s} + {1:s} = {2:s}", len1.toString(UnitSystem::SI), len2.toString(UnitSystem::SI), len3.toString(UnitSyste... | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error: unknown format trait `s` --> LengthClass.rs:152:37 | 152 | println!("{}", format!("{0:s} + {1:s} = {2:s}", len1.toString(UnitSystem::SI), len2.toString(UnitSystem::SI), len3.toString(UnitSyste... | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error: unknown format trait `s` --> LengthClass.rs:152:45 | 152 | println!("{}", format!("{0:s} + {1:s} = {2:s}", len1.toString(UnitSystem::SI), len2.toString(UnitSystem::SI), len3.toString(UnitSyste... | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error: unknown format trait `s` --> LengthClass.rs:153:29 | 153 | println!("{}", format!("{0:s} + {1:s} = {2:s}", len1.toString(UnitSystem::English), len2.toString(UnitSystem::English), len3.toString... | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error: unknown format trait `s` --> LengthClass.rs:153:37 | 153 | println!("{}", format!("{0:s} + {1:s} = {2:s}", len1.toString(UnitSystem::English), len2.toString(UnitSystem::English), len3.toString... | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error: unknown format trait `s` --> LengthClass.rs:153:45 | 153 | println!("{}", format!("{0:s} + {1:s} = {2:s}", len1.toString(UnitSystem::English), len2.toString(UnitSystem::English), len3.toString... | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error: unknown format trait `s` --> LengthClass.rs:155:29 | 155 | println!("{}", format!("{0:s} * {1:.0f} = {2:s}", len1.toString(UnitSystem::SI), 10000.f64, len3.toString(UnitSystem::SI))); | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error: unknown format trait `f` --> LengthClass.rs:155:39 | 155 | println!("{}", format!("{0:s} * {1:.0f} = {2:s}", len1.toString(UnitSystem::SI), 10000.f64, len3.toString(UnitSystem::SI))); | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error: unknown format trait `s` --> LengthClass.rs:155:47 | 155 | println!("{}", format!("{0:s} * {1:.0f} = {2:s}", len1.toString(UnitSystem::SI), 10000.f64, len3.toString(UnitSystem::SI))); | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error: unknown format trait `s` --> LengthClass.rs:156:29 | 156 | println!("{}", format!("{0:s} * {1:.0f} = {2:s}", len1.toString(UnitSystem::English), 10000.f64, len3.toString(UnitSystem::English))); | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error: unknown format trait `f` --> LengthClass.rs:156:39 | 156 | println!("{}", format!("{0:s} * {1:.0f} = {2:s}", len1.toString(UnitSystem::English), 10000.f64, len3.toString(UnitSystem::English))); | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error: unknown format trait `s` --> LengthClass.rs:156:47 | 156 | println!("{}", format!("{0:s} * {1:.0f} = {2:s}", len1.toString(UnitSystem::English), 10000.f64, len3.toString(UnitSystem::English))); | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error: unknown format trait `s` --> LengthClass.rs:158:29 | 158 | println!("{}", format!("{0:s} / {1:.0f} = {2:s}", len1.toString(UnitSystem::SI), 10000.f64, len3.toString(UnitSystem::SI))); | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error: unknown format trait `f` --> LengthClass.rs:158:39 | 158 | println!("{}", format!("{0:s} / {1:.0f} = {2:s}", len1.toString(UnitSystem::SI), 10000.f64, len3.toString(UnitSystem::SI))); | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error: unknown format trait `s` --> LengthClass.rs:158:47 | 158 | println!("{}", format!("{0:s} / {1:.0f} = {2:s}", len1.toString(UnitSystem::SI), 10000.f64, len3.toString(UnitSystem::SI))); | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error: unknown format trait `s` --> LengthClass.rs:159:29 | 159 | println!("{}", format!("{0:s} / {1:.0f} = {2:s}", len1.toString(UnitSystem::English), 10000.f64, len3.toString(UnitSystem::English))); | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error: unknown format trait `f` --> LengthClass.rs:159:39 | 159 | println!("{}", format!("{0:s} / {1:.0f} = {2:s}", len1.toString(UnitSystem::English), 10000.f64, len3.toString(UnitSystem::English))); | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error: unknown format trait `s` --> LengthClass.rs:159:47 | 159 | println!("{}", format!("{0:s} / {1:.0f} = {2:s}", len1.toString(UnitSystem::English), 10000.f64, len3.toString(UnitSystem::English))); | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error[E0424]: expected value, found module `self` --> LengthClass.rs:38:3 | 37 | fn new(value:f64) -> Length { | --- this function doesn't have a `self` parameter 38 | self.value = value; | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 37 | fn new(&self, value:f64) -> Length { | ++++++ error[E0412]: cannot find type `Unit` in this scope --> LengthClass.rs:40:29 | 40 | fn factory(value:f64, unit:Unit) -> Length { | ^^^^ not found in this scope error[E0412]: cannot find type `Unit` in this scope --> LengthClass.rs:70:19 | 70 | fn getValue(unit:Unit) -> f64 { | ^^^^ not found in this scope error[E0424]: expected value, found module `self` --> LengthClass.rs:74:14 | 70 | fn getValue(unit:Unit) -> f64 { | -------- this function doesn't have a `self` parameter ... 74 | result = self.value * 1000; | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 70 | fn getValue(&self, unit:Unit) -> f64 { | ++++++ error[E0424]: expected value, found module `self` --> LengthClass.rs:77:14 | 70 | fn getValue(unit:Unit) -> f64 { | -------- this function doesn't have a `self` parameter ... 77 | result = self.value * 100; | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 70 | fn getValue(&self, unit:Unit) -> f64 { | ++++++ error[E0424]: expected value, found module `self` --> LengthClass.rs:80:14 | 70 | fn getValue(unit:Unit) -> f64 { | -------- this function doesn't have a `self` parameter ... 80 | result = self.value; | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 70 | fn getValue(&self, unit:Unit) -> f64 { | ++++++ error[E0424]: expected value, found module `self` --> LengthClass.rs:83:14 | 70 | fn getValue(unit:Unit) -> f64 { | -------- this function doesn't have a `self` parameter ... 83 | result = self.value / f64::from(1000); | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 70 | fn getValue(&self, unit:Unit) -> f64 { | ++++++ error[E0424]: expected value, found module `self` --> LengthClass.rs:86:14 | 70 | fn getValue(unit:Unit) -> f64 { | -------- this function doesn't have a `self` parameter ... 86 | result = self.value / 0.0254f64; | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 70 | fn getValue(&self, unit:Unit) -> f64 { | ++++++ error[E0424]: expected value, found module `self` --> LengthClass.rs:89:14 | 70 | fn getValue(unit:Unit) -> f64 { | -------- this function doesn't have a `self` parameter ... 89 | result = self.value / 0.3048f64; | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 70 | fn getValue(&self, unit:Unit) -> f64 { | ++++++ error[E0424]: expected value, found module `self` --> LengthClass.rs:92:14 | 70 | fn getValue(unit:Unit) -> f64 { | -------- this function doesn't have a `self` parameter ... 92 | result = self.value / 0.9144f64; | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 70 | fn getValue(&self, unit:Unit) -> f64 { | ++++++ error[E0424]: expected value, found module `self` --> LengthClass.rs:95:14 | 70 | fn getValue(unit:Unit) -> f64 { | -------- this function doesn't have a `self` parameter ... 95 | result = self.value / 1609.344f64; | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 70 | fn getValue(&self, unit:Unit) -> f64 { | ++++++ error[E0424]: expected value, found module `self` --> LengthClass.rs:104:7 | 100 | fn toString(system:UnitSystem) -> String { | -------- this function doesn't have a `self` parameter ... 104 | if self.value < 0.01f64 { | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 100 | fn toString(&self, system:UnitSystem) -> String { | ++++++ error[E0424]: expected value, found module `self` --> LengthClass.rs:105:18 | 100 | fn toString(system:UnitSystem) -> String { | -------- this function doesn't have a `self` parameter ... 105 | finalValue = self.getValue(Unit::millimeter); | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 100 | fn toString(&self, system:UnitSystem) -> String { | ++++++ error[E0424]: expected value, found module `self` --> LengthClass.rs:107:14 | 100 | fn toString(system:UnitSystem) -> String { | -------- this function doesn't have a `self` parameter ... 107 | } else if self.value < 1.0f64 { | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 100 | fn toString(&self, system:UnitSystem) -> String { | ++++++ error[E0424]: expected value, found module `self` --> LengthClass.rs:108:18 | 100 | fn toString(system:UnitSystem) -> String { | -------- this function doesn't have a `self` parameter ... 108 | finalValue = self.getValue(Unit::centimeter); | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 100 | fn toString(&self, system:UnitSystem) -> String { | ++++++ error[E0424]: expected value, found module `self` --> LengthClass.rs:110:14 | 100 | fn toString(system:UnitSystem) -> String { | -------- this function doesn't have a `self` parameter ... 110 | } else if self.value < 1000.f64 { | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 100 | fn toString(&self, system:UnitSystem) -> String { | ++++++ error[E0424]: expected value, found module `self` --> LengthClass.rs:111:18 | 100 | fn toString(system:UnitSystem) -> String { | -------- this function doesn't have a `self` parameter ... 111 | finalValue = self.getValue(Unit::meter); | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 100 | fn toString(&self, system:UnitSystem) -> String { | ++++++ error[E0424]: expected value, found module `self` --> LengthClass.rs:114:18 | 100 | fn toString(system:UnitSystem) -> String { | -------- this function doesn't have a `self` parameter ... 114 | finalValue = self.getValue(Unit::kilometer); | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 100 | fn toString(&self, system:UnitSystem) -> String { | ++++++ error[E0424]: expected value, found module `self` --> LengthClass.rs:118:7 | 100 | fn toString(system:UnitSystem) -> String { | -------- this function doesn't have a `self` parameter ... 118 | if self.value < 0.3048f64 { | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 100 | fn toString(&self, system:UnitSystem) -> String { | ++++++ error[E0424]: expected value, found module `self` --> LengthClass.rs:119:18 | 100 | fn toString(system:UnitSystem) -> String { | -------- this function doesn't have a `self` parameter ... 119 | finalValue = self.getValue(Unit::inch); | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 100 | fn toString(&self, system:UnitSystem) -> String { | ++++++ error[E0424]: expected value, found module `self` --> LengthClass.rs:121:14 | 100 | fn toString(system:UnitSystem) -> String { | -------- this function doesn't have a `self` parameter ... 121 | } else if self.value < 0.9144f64 { | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 100 | fn toString(&self, system:UnitSystem) -> String { | ++++++ error[E0424]: expected value, found module `self` --> LengthClass.rs:122:18 | 100 | fn toString(system:UnitSystem) -> String { | -------- this function doesn't have a `self` parameter ... 122 | finalValue = self.getValue(Unit::foot); | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 100 | fn toString(&self, system:UnitSystem) -> String { | ++++++ error[E0424]: expected value, found module `self` --> LengthClass.rs:124:14 | 100 | fn toString(system:UnitSystem) -> String { | -------- this function doesn't have a `self` parameter ... 124 | } else if self.value < 1609.344f64 { | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 100 | fn toString(&self, system:UnitSystem) -> String { | ++++++ error[E0424]: expected value, found module `self` --> LengthClass.rs:125:18 | 100 | fn toString(system:UnitSystem) -> String { | -------- this function doesn't have a `self` parameter ... 125 | finalValue = self.getValue(Unit::yard); | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 100 | fn toString(&self, system:UnitSystem) -> String { | ++++++ error[E0424]: expected value, found module `self` --> LengthClass.rs:128:18 | 100 | fn toString(system:UnitSystem) -> String { | -------- this function doesn't have a `self` parameter ... 128 | finalValue = self.getValue(Unit::mile); | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 100 | fn toString(&self, system:UnitSystem) -> String { | ++++++ error[E0424]: expected value, found module `self` --> LengthClass.rs:135:18 | 134 | fn add(x:Length) -> Length { | --- this function doesn't have a `self` parameter 135 | return factory(self.value + x.value, Unit::meter); | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 134 | fn add(&self, x:Length) -> Length { | ++++++ error[E0424]: expected value, found module `self` --> LengthClass.rs:138:18 | 137 | fn sub(x:Length) -> Length { | --- this function doesn't have a `self` parameter 138 | return factory(self.value - x.value, Unit::meter); | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 137 | fn sub(&self, x:Length) -> Length { | ++++++ error[E0424]: expected value, found module `self` --> LengthClass.rs:141:18 | 140 | fn mult(x:f64) -> Length { | ---- this function doesn't have a `self` parameter 141 | return factory(self.value * x, Unit::meter); | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 140 | fn mult(&self, x:f64) -> Length { | ++++++ error[E0424]: expected value, found module `self` --> LengthClass.rs:144:18 | 143 | fn div(x:f64) -> Length { | --- this function doesn't have a `self` parameter 144 | return factory(self.value / x, Unit::meter); | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | help: add a `self` receiver parameter to make the associated `fn` a method | 143 | fn div(&self, x:f64) -> Length { | ++++++ error[E0308]: mismatched types --> LengthClass.rs:37:23 | 37 | fn new(value:f64) -> Length { | --- ^^^^^^ expected `Length`, found `()` | | | implicitly returns `()` as its body has no tail or `return` expression error[E0308]: mismatched types --> LengthClass.rs:41:31 | 41 | let mut valueInMeters:f64 = 0; | --- ^ | | | | | expected `f64`, found integer | | help: use a float literal: `0.0` | expected due to this error[E0277]: cannot multiply `f64` by `{integer}` --> LengthClass.rs:53:27 | 53 | valueInMeters = value * 1000; | ^ no implementation for `f64 * {integer}` | = help: the trait `Mul<{integer}>` is not implemented for `f64` = help: the following other types implement trait `Mul<Rhs>`: <&'a f64 as Mul<f64>> <&f64 as Mul<&f64>> <f64 as Mul<&f64>> <f64 as Mul> help: consider using a floating-point literal by writing it with `.0` | 53 | valueInMeters = value * 1000.0; | ++ error[E0308]: mismatched types --> LengthClass.rs:71:24 | 71 | let mut result:f64 = 0; | --- ^ | | | | | expected `f64`, found integer | | help: use a float literal: `0.0` | expected due to this error[E0308]: mismatched types --> LengthClass.rs:101:28 | 101 | let mut finalValue:f64 = 0; | --- ^ | | | | | expected `f64`, found integer | | help: use a float literal: `0.0` | expected due to this error[E0369]: binary operation `==` cannot be applied to type `UnitSystem` --> LengthClass.rs:103:13 | 103 | if system == UnitSystem::SI { | ------ ^^ -------------- UnitSystem | | | UnitSystem | note: an implementation of `PartialEq` might be missing for `UnitSystem` --> LengthClass.rs:9:1 | 9 | enum UnitSystem { | ^^^^^^^^^^^^^^^ must implement `PartialEq` help: consider annotating `UnitSystem` with `#[derive(PartialEq)]` | 9 + #[derive(PartialEq)] 10 | enum UnitSystem { | error[E0433]: failed to resolve: use of undeclared type `Unit` --> LengthClass.rs:105:32 | 105 | finalValue = self.getValue(Unit::millimeter); | ^^^^ use of undeclared type `Unit` error[E0433]: failed to resolve: use of undeclared type `Unit` --> LengthClass.rs:108:32 | 108 | finalValue = self.getValue(Unit::centimeter); | ^^^^ use of undeclared type `Unit` error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> LengthClass.rs:110:32 | 110 | } else if self.value < 1000.f64 { | ^^^ | help: if intended to be a floating point literal, consider adding a `0` after the period | 110 | } else if self.value < 1000.0f64 { | + error[E0433]: failed to resolve: use of undeclared type `Unit` --> LengthClass.rs:111:32 | 111 | finalValue = self.getValue(Unit::meter); | ^^^^ use of undeclared type `Unit` error[E0433]: failed to resolve: use of undeclared type `Unit` --> LengthClass.rs:114:32 | 114 | finalValue = self.getValue(Unit::kilometer); | ^^^^ use of undeclared type `Unit` error[E0433]: failed to resolve: use of undeclared type `Unit` --> LengthClass.rs:119:32 | 119 | finalValue = self.getValue(Unit::inch); | ^^^^ use of undeclared type `Unit` error[E0433]: failed to resolve: use of undeclared type `Unit` --> LengthClass.rs:122:32 | 122 | finalValue = self.getValue(Unit::foot); | ^^^^ use of undeclared type `Unit` error[E0433]: failed to resolve: use of undeclared type `Unit` --> LengthClass.rs:125:32 | 125 | finalValue = self.getValue(Unit::yard); | ^^^^ use of undeclared type `Unit` error[E0433]: failed to resolve: use of undeclared type `Unit` --> LengthClass.rs:128:32 | 128 | finalValue = self.getValue(Unit::mile); | ^^^^ use of undeclared type `Unit` error[E0433]: failed to resolve: use of undeclared type `Unit` --> LengthClass.rs:135:40 | 135 | return factory(self.value + x.value, Unit::meter); | ^^^^ use of undeclared type `Unit` error[E0425]: cannot find function `factory` in this scope --> LengthClass.rs:135:10 | 135 | return factory(self.value + x.value, Unit::meter); | ^^^^^^^ not found in this scope | help: consider using the associated function | 135 | return Self::factory(self.value + x.value, Unit::meter); | ++++++ error[E0433]: failed to resolve: use of undeclared type `Unit` --> LengthClass.rs:138:40 | 138 | return factory(self.value - x.value, Unit::meter); | ^^^^ use of undeclared type `Unit` error[E0425]: cannot find function `factory` in this scope --> LengthClass.rs:138:10 | 138 | return factory(self.value - x.value, Unit::meter); | ^^^^^^^ not found in this scope | help: consider using the associated function | 138 | return Self::factory(self.value - x.value, Unit::meter); | ++++++ error[E0433]: failed to resolve: use of undeclared type `Unit` --> LengthClass.rs:141:34 | 141 | return factory(self.value * x, Unit::meter); | ^^^^ use of undeclared type `Unit` error[E0425]: cannot find function `factory` in this scope --> LengthClass.rs:141:10 | 141 | return factory(self.value * x, Unit::meter); | ^^^^^^^ not found in this scope | help: consider using the associated function | 141 | return Self::factory(self.value * x, Unit::meter); | ++++++ error[E0433]: failed to resolve: use of undeclared type `Unit` --> LengthClass.rs:144:34 | 144 | return factory(self.value / x, Unit::meter); | ^^^^ use of undeclared type `Unit` error[E0425]: cannot find function `factory` in this scope --> LengthClass.rs:144:10 | 144 | return factory(self.value / x, Unit::meter); | ^^^^^^^ not found in this scope | help: consider using the associated function | 144 | return Self::factory(self.value / x, Unit::meter); | ++++++ error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> LengthClass.rs:149:42 | 149 | let mut len1:Length = Length::factory(2.f64, Length::Unit::foot); | ^^^ | help: if intended to be a floating point literal, consider adding a `0` after the period | 149 | let mut len1:Length = Length::factory(2.0f64, Length::Unit::foot); | + error[E0223]: ambiguous associated type --> LengthClass.rs:149:47 | 149 | let mut len1:Length = Length::factory(2.f64, Length::Unit::foot); | ^^^^^^^^^^^^ | help: if there were a trait named `Example` with associated type `Unit` implemented for `Length`, you could use the fully-qualified path | 149 | let mut len1:Length = Length::factory(2.f64, <Length as Example>::Unit::foot); | ~~~~~~~~~~~~~~~~~~~~~~~~~ error[E0223]: ambiguous associated type --> LengthClass.rs:150:48 | 150 | let mut len2:Length = Length::factory(1.5f64, Length::Unit::meter); | ^^^^^^^^^^^^ | help: if there were a trait named `Example` with associated type `Unit` implemented for `Length`, you could use the fully-qualified path | 150 | let mut len2:Length = Length::factory(1.5f64, <Length as Example>::Unit::meter); | ~~~~~~~~~~~~~~~~~~~~~~~~~ error[E0599]: no method named `add` found for struct `Length` in the current scope --> LengthClass.rs:151:29 | 14 | struct Length { | ------------- method `add` not found for this struct ... 151 | let mut len3:Length = len1.add(len2); | -----^^^------ | | | | | this is an associated function, not a method | help: use associated function syntax instead: `Length::add(len2)` | = note: found the following associated functions; to be used as methods, functions must have a `self` parameter note: the candidate is defined in an impl for the type `Length` --> LengthClass.rs:134:2 | 134 | fn add(x:Length) -> Length { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: items from traits can only be used if the trait is implemented and in scope = note: the following trait defines an item `add`, perhaps you need to implement it: candidate #1: `Add` error[E0599]: no method named `toString` found for struct `Length` in the current scope --> LengthClass.rs:152:55 | 14 | struct Length { | ------------- method `toString` not found for this struct ... 152 | println!("{}", format!("{0:s} + {1:s} = {2:s}", len1.toString(UnitSystem::SI), len2.toString(UnitSystem::SI), len3.toString(UnitSyste... | -----^^^^^^^^---------------- | | | | | this is an associated function, not a method | help: use associated function syntax instead: `Length::toString(len1, UnitSystem::SI)` | = note: found the following associated functions; to be used as methods, functions must have a `self` parameter note: the candidate is defined in an impl for the type `Length` --> LengthClass.rs:100:2 | 100 | fn toString(system:UnitSystem) -> String { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0599]: no method named `toString` found for struct `Length` in the current scope --> LengthClass.rs:152:86 | 14 | struct Length { | ------------- method `toString` not found for this struct ... 152 | println!("{}", format!("{0:s} + {1:s} = {2:s}", len1.toString(UnitSystem::SI), len2.toString(UnitSystem::SI), len3.toString(UnitSyste... | -----^^^^^^^^---------------- | | | | | this is an associated function, not a method | help: use associated function syntax instead: `Length::toString(len2, UnitSystem::SI)` | = note: found the following associated functions; to be used as methods, functions must have a `self` parameter note: the candidate is defined in an impl for the type `Length` --> LengthClass.rs:100:2 | 100 | fn toString(system:UnitSystem) -> String { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0599]: no method named `toString` found for struct `Length` in the current scope --> LengthClass.rs:153:55 | 14 | struct Length { | ------------- method `toString` not found for this struct ... 153 | println!("{}", format!("{0:s} + {1:s} = {2:s}", len1.toString(UnitSystem::English), len2.toString(UnitSystem::English), len3.toString... | -----^^^^^^^^--------------------- | | | | | this is an associated function, not a method | help: use associated function syntax instead: `Length::toString(len1, UnitSystem::English)` | = note: found the following associated functions; to be used as methods, functions must have a `self` parameter note: the candidate is defined in an impl for the type `Length` --> LengthClass.rs:100:2 | 100 | fn toString(system:UnitSystem) -> String { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0599]: no method named `toString` found for struct `Length` in the current scope --> LengthClass.rs:153:91 | 14 | struct Length { | ------------- method `toString` not found for this struct ... 153 | println!("{}", format!("{0:s} + {1:s} = {2:s}", len1.toString(UnitSystem::English), len2.toString(UnitSystem::English), len3.toString... | -----^^^^^^^^--------------------- | | | | | this is an associated function, not a method | help: use associated function syntax instead: `Length::toString(len2, UnitSystem::English)` | = note: found the following associated functions; to be used as methods, functions must have a `self` parameter note: the candidate is defined in an impl for the type `Length` --> LengthClass.rs:100:2 | 100 | fn toString(system:UnitSystem) -> String { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0599]: no method named `mult` found for struct `Length` in the current scope --> LengthClass.rs:154:14 | 14 | struct Length { | ------------- method `mult` not found for this struct ... 154 | len3 = len1.mult(10000.f64); | -----^^^^----------- | | | | | this is an associated function, not a method | help: use associated function syntax instead: `Length::mult(len1, 10000.f64)` | = note: found the following associated functions; to be used as methods, functions must have a `self` parameter note: the candidate is defined in an impl for the type `Length` --> LengthClass.rs:140:2 | 140 | fn mult(x:f64) -> Length { | ^^^^^^^^^^^^^^^^^^^^^^^^ error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> LengthClass.rs:154:25 | 154 | len3 = len1.mult(10000.f64); | ^^^ | help: if intended to be a floating point literal, consider adding a `0` after the period | 154 | len3 = len1.mult(10000.0f64); | + error[E0599]: no method named `toString` found for struct `Length` in the current scope --> LengthClass.rs:155:57 | 14 | struct Length { | ------------- method `toString` not found for this struct ... 155 | println!("{}", format!("{0:s} * {1:.0f} = {2:s}", len1.toString(UnitSystem::SI), 10000.f64, len3.toString(UnitSystem::SI))); | -----^^^^^^^^---------------- | | | | | this is an associated function, not a method | help: use associated function syntax instead: `Length::toString(len1, UnitSystem::SI)` | = note: found the following associated functions; to be used as methods, functions must have a `self` parameter note: the candidate is defined in an impl for the type `Length` --> LengthClass.rs:100:2 | 100 | fn toString(system:UnitSystem) -> String { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> LengthClass.rs:155:89 | 155 | println!("{}", format!("{0:s} * {1:.0f} = {2:s}", len1.toString(UnitSystem::SI), 10000.f64, len3.toString(UnitSystem::SI))); | ^^^ | help: if intended to be a floating point literal, consider adding a `0` after the period | 155 | println!("{}", format!("{0:s} * {1:.0f} = {2:s}", len1.toString(UnitSystem::SI), 10000.0f64, len3.toString(UnitSystem::SI))); | + error[E0599]: no method named `toString` found for struct `Length` in the current scope --> LengthClass.rs:156:57 | 14 | struct Length { | ------------- method `toString` not found for this struct ... 156 | println!("{}", format!("{0:s} * {1:.0f} = {2:s}", len1.toString(UnitSystem::English), 10000.f64, len3.toString(UnitSystem::English))); | -----^^^^^^^^--------------------- | | | | | this is an associated function, not a method | help: use associated function syntax instead: `Length::toString(len1, UnitSystem::English)` | = note: found the following associated functions; to be used as methods, functions must have a `self` parameter note: the candidate is defined in an impl for the type `Length` --> LengthClass.rs:100:2 | 100 | fn toString(system:UnitSystem) -> String { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> LengthClass.rs:156:94 | 156 | println!("{}", format!("{0:s} * {1:.0f} = {2:s}", len1.toString(UnitSystem::English), 10000.f64, len3.toString(UnitSystem::English))); | ^^^ | help: if intended to be a floating point literal, consider adding a `0` after the period | 156 | println!("{}", format!("{0:s} * {1:.0f} = {2:s}", len1.toString(UnitSystem::English), 10000.0f64, len3.toString(UnitSystem::English))); | + error[E0599]: no method named `div` found for struct `Length` in the current scope --> LengthClass.rs:157:14 | 14 | struct Length { | ------------- method `div` not found for this struct ... 157 | len3 = len2.div(10000.f64); | -----^^^----------- | | | | | this is an associated function, not a method | help: use associated function syntax instead: `Length::div(len2, 10000.f64)` | = note: found the following associated functions; to be used as methods, functions must have a `self` parameter note: the candidate is defined in an impl for the type `Length` --> LengthClass.rs:143:2 | 143 | fn div(x:f64) -> Length { | ^^^^^^^^^^^^^^^^^^^^^^^ = help: items from traits can only be used if the trait is implemented and in scope = note: the following trait defines an item `div`, perhaps you need to implement it: candidate #1: `Div` error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> LengthClass.rs:157:24 | 157 | len3 = len2.div(10000.f64); | ^^^ | help: if intended to be a floating point literal, consider adding a `0` after the period | 157 | len3 = len2.div(10000.0f64); | + error[E0599]: no method named `toString` found for struct `Length` in the current scope --> LengthClass.rs:158:57 | 14 | struct Length { | ------------- method `toString` not found for this struct ... 158 | println!("{}", format!("{0:s} / {1:.0f} = {2:s}", len1.toString(UnitSystem::SI), 10000.f64, len3.toString(UnitSystem::SI))); | -----^^^^^^^^---------------- | | | | | this is an associated function, not a method | help: use associated function syntax instead: `Length::toString(len1, UnitSystem::SI)` | = note: found the following associated functions; to be used as methods, functions must have a `self` parameter note: the candidate is defined in an impl for the type `Length` --> LengthClass.rs:100:2 | 100 | fn toString(system:UnitSystem) -> String { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> LengthClass.rs:158:89 | 158 | println!("{}", format!("{0:s} / {1:.0f} = {2:s}", len1.toString(UnitSystem::SI), 10000.f64, len3.toString(UnitSystem::SI))); | ^^^ | help: if intended to be a floating point literal, consider adding a `0` after the period | 158 | println!("{}", format!("{0:s} / {1:.0f} = {2:s}", len1.toString(UnitSystem::SI), 10000.0f64, len3.toString(UnitSystem::SI))); | + error[E0599]: no method named `toString` found for struct `Length` in the current scope --> LengthClass.rs:159:57 | 14 | struct Length { | ------------- method `toString` not found for this struct ... 159 | println!("{}", format!("{0:s} / {1:.0f} = {2:s}", len1.toString(UnitSystem::English), 10000.f64, len3.toString(UnitSystem::English))); | -----^^^^^^^^--------------------- | | | | | this is an associated function, not a method | help: use associated function syntax instead: `Length::toString(len1, UnitSystem::English)` | = note: found the following associated functions; to be used as methods, functions must have a `self` parameter note: the candidate is defined in an impl for the type `Length` --> LengthClass.rs:100:2 | 100 | fn toString(system:UnitSystem) -> String { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> LengthClass.rs:159:94 | 159 | println!("{}", format!("{0:s} / {1:.0f} = {2:s}", len1.toString(UnitSystem::English), 10000.f64, len3.toString(UnitSystem::English))); | ^^^ | help: if intended to be a floating point literal, consider adding a `0` after the period | 159 | println!("{}", format!("{0:s} / {1:.0f} = {2:s}", len1.toString(UnitSystem::English), 10000.0f64, len3.toString(UnitSystem::English))); | + error[E0433]: failed to resolve: use of undeclared type `Unit` --> LengthClass.rs:43:4 | 43 | Unit::millimeter => { | ^^^^ use of undeclared type `Unit` error[E0433]: failed to resolve: use of undeclared type `Unit` --> LengthClass.rs:46:4 | 46 | Unit::centimeter => { | ^^^^ use of undeclared type `Unit` error[E0433]: failed to resolve: use of undeclared type `Unit` --> LengthClass.rs:49:4 | 49 | Unit::meter => { | ^^^^ use of undeclared type `Unit` error[E0433]: failed to resolve: use of undeclared type `Unit` --> LengthClass.rs:52:4 | 52 | Unit::kilometer => { | ^^^^ use of undeclared type `Unit` error[E0433]: failed to resolve: use of undeclared type `Unit` --> LengthClass.rs:55:4 | 55 | Unit::inch => { | ^^^^ use of undeclared type `Unit` error[E0433]: failed to resolve: use of undeclared type `Unit` --> LengthClass.rs:58:4 | 58 | Unit::foot => { | ^^^^ use of undeclared type `Unit` error[E0433]: failed to resolve: use of undeclared type `Unit` --> LengthClass.rs:61:4 | 61 | Unit::yard => { | ^^^^ use of undeclared type `Unit` error[E0433]: failed to resolve: use of undeclared type `Unit` --> LengthClass.rs:64:4 | 64 | Unit::mile => { | ^^^^ use of undeclared type `Unit` error[E0433]: failed to resolve: use of undeclared type `Unit` --> LengthClass.rs:73:4 | 73 | Unit::millimeter => { | ^^^^ use of undeclared type `Unit` error[E0433]: failed to resolve: use of undeclared type `Unit` --> LengthClass.rs:76:4 | 76 | Unit::centimeter => { | ^^^^ use of undeclared type `Unit` error[E0433]: failed to resolve: use of undeclared type `Unit` --> LengthClass.rs:79:4 | 79 | Unit::meter => { | ^^^^ use of undeclared type `Unit` error[E0433]: failed to resolve: use of undeclared type `Unit` --> LengthClass.rs:82:4 | 82 | Unit::kilometer => { | ^^^^ use of undeclared type `Unit` error[E0433]: failed to resolve: use of undeclared type `Unit` --> LengthClass.rs:85:4 | 85 | Unit::inch => { | ^^^^ use of undeclared type `Unit` error[E0433]: failed to resolve: use of undeclared type `Unit` --> LengthClass.rs:88:4 | 88 | Unit::foot => { | ^^^^ use of undeclared type `Unit` error[E0433]: failed to resolve: use of undeclared type `Unit` --> LengthClass.rs:91:4 | 91 | Unit::yard => { | ^^^^ use of undeclared type `Unit` error[E0433]: failed to resolve: use of undeclared type `Unit` --> LengthClass.rs:94:4 | 94 | Unit::mile => { | ^^^^ use of undeclared type `Unit` error: aborting due to 109 previous errors Some errors have detailed explanations: E0223, E0277, E0308, E0369, E0412, E0424, E0425, E0433, E0599... For more information about an error, try `rustc --explain E0223`.

Solution