Closed
Description
First, create new lib with type alias and function:
pub type OperationType = String;
lazy_static! {
pub static ref OPERATION_TYPE_BUY: OperationType = String::from("Buy");
}
pub fn limit_order(
&self,
account_id: &str,
figi: &str,
lots: i64,
operation: OperationType,
price: f64,
) -> Result<PlacedOrder> {
...
}
Then, we use this crate in our program:
let limit_order =
rest_client.limit_order("", "BBG000BB88K4", 2, OPERATION_TYPE_BUY, 11 as f64)?;
OPERATION_TYPE_BUY
has type OperationType
, this type we expect in limit_order
function, but we have error:
error[E0308]: mismatched types
--> src/main.rs:38:57
|
38 | rest_client.limit_order("", "BBG000BB88K4", 2, OPERATION_TYPE_BUY, 11 as f64)?;
| ^^^^^^^^^^^^^^^^^^
| |
| expected struct `std::string::String`, found struct `invest_openapi_rs_sdk::OPERATION_TYPE_BUY`
| help: try using a conversion method: `OPERATION_TYPE_BUY.to_string()`
error: aborting due to previous error
If our function expect OperationType
type, why rust asked me convert to String?
Meta
rustc --version --verbose
:
$ rustc --version --verbose
rustc 1.46.0 (04488afe3 2020-08-24)
binary: rustc
commit-hash: 04488afe34512aa4c33566eb16d8c912a3ae04f9
commit-date: 2020-08-24
host: x86_64-apple-darwin
release: 1.46.0
LLVM version: 10.0