Project: Currency Class
Write a class for converting between different currencies. The class should be immutable. Create a single constructor that takes a double value and a string representing the currency. Write a getter that take a currency type string and returns the value in that currency as a double. Include currencies for USD, EUR, JPY, GBP, CAD, CNY, RUB, MXN, AUD, INR and Bitcoin (XBT). Have a method for setting the current conversion rates by passing a map. Also have a toString() like method that takes a currency code and then returns the value formatted with its currency symbol.
See [[wikipidea or link]] See other project
Output
$ rustc CurrencyClass.rs
error: expected identifier, found keyword `static`
--> CurrencyClass.rs:17:2
|
13 | struct Currency {
| -------- while parsing this struct
...
17 | static static mut conversionRates:HashMap<String, f64> = HashMap::new();
| ^^^^^^ expected identifier, found keyword
error: this is a block expression, not an array
--> CurrencyClass.rs:113:3
|
113 | {"AUD", 1.26f64},
| ^^^^^^^^^^^^^^^^
|
help: to make an array, use square brackets instead of curly braces
|
113 | ["AUD", 1.26f64],
| ~ ~
error: this is a block expression, not an array
--> CurrencyClass.rs:114:3
|
114 | {"CAD", 1.26f64},
| ^^^^^^^^^^^^^^^^
|
help: to make an array, use square brackets instead of curly braces
|
114 | ["CAD", 1.26f64],
| ~ ~
error: this is a block expression, not an array
--> CurrencyClass.rs:115:3
|
115 | {"CNY", 6.47f64},
| ^^^^^^^^^^^^^^^^
|
help: to make an array, use square brackets instead of curly braces
|
115 | ["CNY", 6.47f64],
| ~ ~
error: this is a block expression, not an array
--> CurrencyClass.rs:116:3
|
116 | {"EUR", 0.82f64},
| ^^^^^^^^^^^^^^^^
|
help: to make an array, use square brackets instead of curly braces
|
116 | ["EUR", 0.82f64],
| ~ ~
error: this is a block expression, not an array
--> CurrencyClass.rs:117:3
|
117 | {"GBP", 0.71f64},
| ^^^^^^^^^^^^^^^^
|
help: to make an array, use square brackets instead of curly braces
|
117 | ["GBP", 0.71f64],
| ~ ~
error: this is a block expression, not an array
--> CurrencyClass.rs:118:3
|
118 | {"INR", 72.49f64},
| ^^^^^^^^^^^^^^^^^
|
help: to make an array, use square brackets instead of curly braces
|
118 | ["INR", 72.49f64],
| ~ ~
error: this is a block expression, not an array
--> CurrencyClass.rs:119:3
|
119 | {"JPY", 105.07f64},
| ^^^^^^^^^^^^^^^^^^
|
help: to make an array, use square brackets instead of curly braces
|
119 | ["JPY", 105.07f64],
| ~ ~
error: this is a block expression, not an array
--> CurrencyClass.rs:120:3
|
120 | {"MXN", 20.68f64},
| ^^^^^^^^^^^^^^^^^
|
help: to make an array, use square brackets instead of curly braces
|
120 | ["MXN", 20.68f64],
| ~ ~
error: this is a block expression, not an array
--> CurrencyClass.rs:121:3
|
121 | {"RUB", 74.29f64},
| ^^^^^^^^^^^^^^^^^
|
help: to make an array, use square brackets instead of curly braces
|
121 | ["RUB", 74.29f64],
| ~ ~
error: this is a block expression, not an array
--> CurrencyClass.rs:122:3
|
122 | {"USD", 1.0f64},
| ^^^^^^^^^^^^^^^
|
help: to make an array, use square brackets instead of curly braces
|
122 | ["USD", 1.0f64],
| ~ ~
error: this is a block expression, not an array
--> CurrencyClass.rs:123:3
|
123 | {"XBT", 0.00001900f64}
| ^^^^^^^^^^^^^^^^^^^^^^
|
help: to make an array, use square brackets instead of curly braces
|
123 | ["XBT", 0.00001900f64]
| ~ ~
error: unknown format trait `f`
--> CurrencyClass.rs:74:32
|
74 | let s:String = format!("{0:.2f}", d);
| ^
|
= 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: format argument must be a string literal
--> CurrencyClass.rs:103:18
|
103 | return format!(formatStr, currencySymbol, currencyValue);
| ^^^^^^^^^
|
help: you might be missing a string literal to format with
|
103 | return format!("{} {} {}", formatStr, currencySymbol, currencyValue);
| +++++++++++
error: unknown format trait `s`
--> CurrencyClass.rs:130:31
|
130 | println!("{}", format!("{0:s} to {1:s}: {2:s} = {3:s}", "USD", code, c.getString("USD"), c.getString(&code)));
| ^
|
= 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`
--> CurrencyClass.rs:130:40
|
130 | println!("{}", format!("{0:s} to {1:s}: {2:s} = {3:s}", "USD", code, c.getString("USD"), c.getString(&code)));
| ^
|
= 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`
--> CurrencyClass.rs:130:47
|
130 | println!("{}", format!("{0:s} to {1:s}: {2:s} = {3:s}", "USD", code, c.getString("USD"), c.getString(&code)));
| ^
|
= 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`
--> CurrencyClass.rs:130:55
|
130 | println!("{}", format!("{0:s} to {1:s}: {2:s} = {3:s}", "USD", code, c.getString("USD"), c.getString(&code)));
| ^
|
= 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`
--> CurrencyClass.rs:136:31
|
136 | println!("{}", format!("{0:s} to {1:s}: {2:s} = {3:s}", "USD", code, c.getString("USD"), c.getString(&code)));
| ^
|
= 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`
--> CurrencyClass.rs:136:40
|
136 | println!("{}", format!("{0:s} to {1:s}: {2:s} = {3:s}", "USD", code, c.getString("USD"), c.getString(&code)));
| ^
|
= 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`
--> CurrencyClass.rs:136:47
|
136 | println!("{}", format!("{0:s} to {1:s}: {2:s} = {3:s}", "USD", code, c.getString("USD"), c.getString(&code)));
| ^
|
= 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`
--> CurrencyClass.rs:136:55
|
136 | println!("{}", format!("{0:s} to {1:s}: {2:s} = {3:s}", "USD", code, c.getString("USD"), c.getString(&code)));
| ^
|
= 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[E0432]: unresolved import `regex`
--> CurrencyClass.rs:8:5
|
8 | use regex::Regex;
| ^^^^^ maybe a missing crate `regex`?
|
= help: consider adding `extern crate regex` to use the `regex` crate
error[E0425]: cannot find value `conversionRates` in this scope
--> CurrencyClass.rs:57:18
|
57 | if mapContains(conversionRates,currencyCode) {
| ^^^^^^^^^^^^^^^ help: a local variable with a similar name exists: `conversionRate`
error[E0425]: cannot find value `conversionRates` in this scope
--> CurrencyClass.rs:58:21
|
58 | conversionRate = conversionRates.at(currencyCode);
| ^^^^^^^^^^^^^^^ help: a local variable with a similar name exists: `conversionRate`
error[E0424]: expected value, found module `self`
--> CurrencyClass.rs:62:3
|
55 | fn new(value:f64, currencyCode:&str) -> Currency {
| --- this function doesn't have a `self` parameter
...
62 | self.value = value / conversionRate;
| ^^^^ `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
|
55 | fn new(&self, value:f64, currencyCode:&str) -> Currency {
| ++++++
error[E0425]: cannot find value `conversionRates` in this scope
--> CurrencyClass.rs:66:18
|
66 | if mapContains(conversionRates,currencyCode) {
| ^^^^^^^^^^^^^^^ help: a local variable with a similar name exists: `conversionRate`
error[E0425]: cannot find value `conversionRates` in this scope
--> CurrencyClass.rs:67:21
|
67 | conversionRate = conversionRates.at(currencyCode);
| ^^^^^^^^^^^^^^^ help: a local variable with a similar name exists: `conversionRate`
error[E0424]: expected value, found module `self`
--> CurrencyClass.rs:71:10
|
64 | fn get(currencyCode:&str) -> Result<f64, Arc<dyn error::Error>> {
| --- this function doesn't have a `self` parameter
...
71 | return self.value * conversionRate;
| ^^^^ `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
|
64 | fn get(&self, currencyCode:&str) -> Result<f64, Arc<dyn error::Error>> {
| ++++++
error[E0425]: cannot find value `currencySymbols` in this scope
--> CurrencyClass.rs:91:18
|
91 | if mapContains(currencySymbols,currencyCode) {
| ^^^^^^^^^^^^^^^ help: a local variable with a similar name exists: `currencySymbol`
error[E0425]: cannot find value `currencySymbols` in this scope
--> CurrencyClass.rs:92:23
|
92 | currencySymbol = &(currencySymbols.at(currencyCode));
| ^^^^^^^^^^^^^^^ help: a local variable with a similar name exists: `currencySymbol`
error[E0425]: cannot find value `currencySeparators` in this scope
--> CurrencyClass.rs:93:26
|
93 | currencySeparator = &(currencySeparators.at(currencyCode));
| ^^^^^^^^^^^^^^^^^^ help: a local variable with a similar name exists: `currencySeparator`
error[E0424]: expected value, found module `self`
--> CurrencyClass.rs:97:56
|
88 | fn getString(currencyCode:&str) -> Result<String, Arc<dyn error::Error>> {
| --------- this function doesn't have a `self` parameter
...
97 | if strlen(currencySymbol) > 1 && find(currencySymbol,self.nonbreakingSpace) == 0 {
| ^^^^ `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
|
88 | fn getString(&self, currencyCode:&str) -> Result<String, Arc<dyn error::Error>> {
| ++++++
error[E0424]: expected value, found module `self`
--> CurrencyClass.rs:102:30
|
88 | fn getString(currencyCode:&str) -> Result<String, Arc<dyn error::Error>> {
| --------- this function doesn't have a `self` parameter
...
102 | let currencyValue:String = self.addSeparators(self.get(currencyCode), currencySeparator);
| ^^^^ `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
|
88 | fn getString(&self, currencyCode:&str) -> Result<String, Arc<dyn error::Error>> {
| ++++++
error[E0424]: expected value, found module `self`
--> CurrencyClass.rs:102:49
|
88 | fn getString(currencyCode:&str) -> Result<String, Arc<dyn error::Error>> {
| --------- this function doesn't have a `self` parameter
...
102 | let currencyValue:String = self.addSeparators(self.get(currencyCode), currencySeparator);
| ^^^^ `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
|
88 | fn getString(&self, currencyCode:&str) -> Result<String, Arc<dyn error::Error>> {
| ++++++
error[E0425]: cannot find value `conversionRates` in this scope
--> CurrencyClass.rs:106:3
|
106 | conversionRates = rates;
| ^^^^^^^^^^^^^^^
|
help: you might have meant to introduce a new binding
|
106 | let conversionRates = rates;
| +++
error[E0425]: cannot find value `currencyCodes` in this scope
--> CurrencyClass.rs:107:3
|
107 | currencyCodes = sortedKeys(conversionRates);
| ^^^^^^^^^^^^^
|
help: you might have meant to introduce a new binding
|
107 | let currencyCodes = sortedKeys(conversionRates);
| +++
error[E0425]: cannot find value `conversionRates` in this scope
--> CurrencyClass.rs:107:30
|
107 | currencyCodes = sortedKeys(conversionRates);
| ^^^^^^^^^^^^^^^ not found in this scope
error[E0425]: cannot find function `mapContains` in this scope
--> CurrencyClass.rs:57:6
|
57 | if mapContains(conversionRates,currencyCode) {
| ^^^^^^^^^^^ not found in this scope
error[E0308]: mismatched types
--> CurrencyClass.rs:60:11
|
55 | fn new(value:f64, currencyCode:&str) -> Currency {
| -------- expected `Currency` because of return type
...
60 | return Err(Arc::new(utils::CustomError::RuntimeError(String::from("Illegal currency code: ") + currencyCode)));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Currency`, found `Result<_, Arc<CustomError>>`
|
= note: expected struct `Currency`
found enum `Result<_, Arc<CustomError>>`
error[E0308]: mismatched types
--> CurrencyClass.rs:55:42
|
55 | fn new(value:f64, currencyCode:&str) -> Currency {
| --- ^^^^^^^^ expected `Currency`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
error[E0425]: cannot find function `mapContains` in this scope
--> CurrencyClass.rs:66:6
|
66 | if mapContains(conversionRates,currencyCode) {
| ^^^^^^^^^^^ not found in this scope
error[E0277]: the type `str` cannot be indexed by `{integer}`
--> CurrencyClass.rs:75:24
|
75 | let comma:char = sep[0];
| ^ string indices are ranges of `usize`
|
= help: the trait `SliceIndex<str>` is not implemented for `{integer}`
= note: you can use `.chars().nth()` or `.bytes().nth()`
for more information, see chapter 8 in The Book: <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>
= help: the trait `SliceIndex<[T]>` is implemented for `usize`
= note: required for `str` to implement `Index<{integer}>`
error[E0277]: the type `str` cannot be indexed by `{integer}`
--> CurrencyClass.rs:76:25
|
76 | let period:char = sep[1];
| ^ string indices are ranges of `usize`
|
= help: the trait `SliceIndex<str>` is not implemented for `{integer}`
= note: you can use `.chars().nth()` or `.bytes().nth()`
for more information, see chapter 8 in The Book: <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>
= help: the trait `SliceIndex<[T]>` is implemented for `usize`
= note: required for `str` to implement `Index<{integer}>`
error[E0425]: cannot find function `split` in this scope
--> CurrencyClass.rs:77:27
|
77 | let parts:Vec<String> = split(s,Regex::new(r"\\.").unwrap());
| ^^^^^ not found in this scope
error[E0425]: cannot find function `findFirst` in this scope
--> CurrencyClass.rs:81:13
|
81 | matches = findFirst(dollars,pattern);
| ^^^^^^^^^ not found in this scope
error[E0308]: mismatched types
--> CurrencyClass.rs:83:27
|
83 | dollars = matches[1] + comma + &matches[2];
| ^^^^^ expected `&str`, found `char`
error[E0425]: cannot find function `findFirst` in this scope
--> CurrencyClass.rs:84:14
|
84 | matches = findFirst(dollars,pattern);
| ^^^^^^^^^ not found in this scope
error[E0425]: cannot find function `mapContains` in this scope
--> CurrencyClass.rs:91:6
|
91 | if mapContains(currencySymbols,currencyCode) {
| ^^^^^^^^^^^ not found in this scope
error[E0425]: cannot find function `strlen` in this scope
--> CurrencyClass.rs:97:6
|
97 | if strlen(currencySymbol) > 1 && find(currencySymbol,self.nonbreakingSpace) == 0 {
| ^^^^^^ not found in this scope
error[E0425]: cannot find function `find` in this scope
--> CurrencyClass.rs:97:36
|
97 | if strlen(currencySymbol) > 1 && find(currencySymbol,self.nonbreakingSpace) == 0 {
| ^^^^ not found in this scope
|
help: use the `.` operator to call the method `find` on `&str`
|
97 - if strlen(currencySymbol) > 1 && find(currencySymbol,self.nonbreakingSpace) == 0 {
97 + if strlen(currencySymbol) > 1 && currencySymbol.find(self.nonbreakingSpace) == 0 {
|
error[E0308]: mismatched types
--> CurrencyClass.rs:97:82
|
97 | if strlen(currencySymbol) > 1 && find(currencySymbol,self.nonbreakingSpace) == 0 {
| ------------------------------------------ ^ expected `Option<usize>`, found integer
| |
| expected because this is `Option<usize>`
|
= note: expected enum `Option<usize>`
found type `{integer}`
help: try wrapping the expression in `Some`
|
97 | if strlen(currencySymbol) > 1 && find(currencySymbol,self.nonbreakingSpace) == Some(0) {
| +++++ +
error[E0308]: mismatched types
--> CurrencyClass.rs:103:10
|
103 | return format!(formatStr, currencySymbol, currencyValue);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<String, Arc<dyn Error>>`, found `String`
|
= note: expected enum `Result<String, Arc<(dyn std::error::Error + 'static)>>`
found struct `String`
= note: this error originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0425]: cannot find function `sortedKeys` in this scope
--> CurrencyClass.rs:107:19
|
107 | currencyCodes = sortedKeys(conversionRates);
| ^^^^^^^^^^ not found in this scope
error[E0599]: no function or associated item named `currencyCodes` found for struct `Currency` in the current scope
--> CurrencyClass.rs:129:25
|
13 | struct Currency {
| --------------- function or associated item `currencyCodes` not found for this struct
...
129 | for code in Currency::currencyCodes {
| ^^^^^^^^^^^^^ function or associated item not found in `Currency`
error[E0599]: no method named `getString` found for struct `Currency` in the current scope
--> CurrencyClass.rs:130:75
|
13 | struct Currency {
| --------------- method `getString` not found for this struct
...
130 | println!("{}", format!("{0:s} to {1:s}: {2:s} = {3:s}", "USD", code, c.getString("USD"), c.getString(&code)));
| --^^^^^^^^^-------
| | |
| | this is an associated function, not a method
| help: use associated function syntax instead: `Currency::getString(&c, "USD")`
|
= 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 `Currency`
--> CurrencyClass.rs:88:2
|
88 | fn getString(currencyCode:&str) -> Result<String, Arc<dyn error::Error>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0599]: no method named `getString` found for struct `Currency` in the current scope
--> CurrencyClass.rs:130:95
|
13 | struct Currency {
| --------------- method `getString` not found for this struct
...
130 | println!("{}", format!("{0:s} to {1:s}: {2:s} = {3:s}", "USD", code, c.getString("USD"), c.getString(&code)));
| --^^^^^^^^^-------
| | |
| | this is an associated function, not a method
| help: use associated function syntax instead: `Currency::getString(&c, &code)`
|
= 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 `Currency`
--> CurrencyClass.rs:88:2
|
88 | fn getString(currencyCode:&str) -> Result<String, Arc<dyn error::Error>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0599]: no function or associated item named `currencyCodes` found for struct `Currency` in the current scope
--> CurrencyClass.rs:135:25
|
13 | struct Currency {
| --------------- function or associated item `currencyCodes` not found for this struct
...
135 | for code in Currency::currencyCodes {
| ^^^^^^^^^^^^^ function or associated item not found in `Currency`
error[E0599]: no method named `getString` found for struct `Currency` in the current scope
--> CurrencyClass.rs:136:75
|
13 | struct Currency {
| --------------- method `getString` not found for this struct
...
136 | println!("{}", format!("{0:s} to {1:s}: {2:s} = {3:s}", "USD", code, c.getString("USD"), c.getString(&code)));
| --^^^^^^^^^-------
| | |
| | this is an associated function, not a method
| help: use associated function syntax instead: `Currency::getString(&c, "USD")`
|
= 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 `Currency`
--> CurrencyClass.rs:88:2
|
88 | fn getString(currencyCode:&str) -> Result<String, Arc<dyn error::Error>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0599]: no method named `getString` found for struct `Currency` in the current scope
--> CurrencyClass.rs:136:95
|
13 | struct Currency {
| --------------- method `getString` not found for this struct
...
136 | println!("{}", format!("{0:s} to {1:s}: {2:s} = {3:s}", "USD", code, c.getString("USD"), c.getString(&code)));
| --^^^^^^^^^-------
| | |
| | this is an associated function, not a method
| help: use associated function syntax instead: `Currency::getString(&c, &code)`
|
= 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 `Currency`
--> CurrencyClass.rs:88:2
|
88 | fn getString(currencyCode:&str) -> Result<String, Arc<dyn error::Error>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 60 previous errors
Some errors have detailed explanations: E0277, E0308, E0424, E0425, E0432, E0599.
For more information about an error, try `rustc --explain E0277`.