株のシステムトレードをしよう - 1から始める株自動取引システムの作り方

株式をコンピュータに売買させる仕組みを少しずつ作っていきます。できあがってから公開ではなく、書いたら途中でも記事として即掲載して、後から固定ページにして体裁を整える方式で進めていきます。

DBへCSVをインポートするツールを作っている その15 - Dieselのセットアップその6

Rustのエラーと闘っている。。。言語使用は流し見しかしてないから、具体的なエラー文を読んで、1個1個対処していく。

error[E0433]: failed to resolve: could not find `diesel` in the crate root
  --> src/main.rs:13:11
   |
13 | use self::diesel::prelude::*;
   |           ^^^^^^ could not find `diesel` in the crate root

error[E0599]: the method `filter` exists for struct `table`, but its trait bounds were not satisfied
  --> src/main.rs:21:26
   |
21 |       let results = stocks.filter(code.eq(given_code as time_and_sales_deliver::schema::stocks::code))
   |                            ^^^^^^ method cannot be called on `table` due to unsatisfied trait bounds
   | 
  ::: /app/src/schema.rs:1:1
   |
1  | / table! {
2  | |     stocks (code, datetime) {
3  | |         code -> Int4,
4  | |         datetime -> Timestamp,
...  |
7  | |     }
8  | | }
   | |_- doesn't satisfy `table: Iterator`
   |
   = note: the following trait bounds were not satisfied:
           `table: Iterator`
           which is required by `&mut table: Iterator`
   = help: items from traits can only be used if the trait is in scope
help: the following traits are implemented but not in scope; perhaps add a `use` for one of them:
   |
3  | use std::iter::Iterator;
   |
3  | use diesel::query_dsl::filter_dsl::FilterDsl;
   |
3  | use diesel::query_dsl::QueryDsl;
   |
3  | use futures::StreamExt;
   |
     and 1 other candidate

error[E0599]: the method `eq` exists for struct `time_and_sales_deliver::schema::stocks::code`, but its trait bounds were not satisfied
  --> src/main.rs:21:38
   |
21 |       let results = stocks.filter(code.eq(given_code as time_and_sales_deliver::schema::stocks::code))
   |                                        ^^ method cannot be called on `time_and_sales_deliver::schema::stocks::code` due to unsatisfied trait bounds
   | 
  ::: /app/src/schema.rs:1:1
   |
1  | / table! {
2  | |     stocks (code, datetime) {
3  | |         code -> Int4,
4  | |         datetime -> Timestamp,
...  |
7  | |     }
8  | | }
   | |_- doesn't satisfy `_: Iterator`
   |
   = note: the following trait bounds were not satisfied:
           `time_and_sales_deliver::schema::stocks::code: Iterator`
           which is required by `&mut time_and_sales_deliver::schema::stocks::code: Iterator`
   = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
   |
3  | use diesel::expression_methods::global_expression_methods::ExpressionMethods;
   |

error[E0605]: non-primitive cast: `String` as `time_and_sales_deliver::schema::stocks::code`
  --> src/main.rs:21:41
   |
21 |     let results = stocks.filter(code.eq(given_code as time_and_sales_deliver::schema::stocks::code))
   |                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object

error[E0308]: mismatched types
  --> src/main.rs:29:27
   |
29 | async fn index(web::Path((code, datetime)): web::Path<(String, String)>) -> impl Responder {
   |                -----------^^^^------------
   |                |          |
   |                |          expected struct `String`, found struct `time_and_sales_deliver::schema::stocks::code`
   |                this expression has type `actix_web::web::Path<(String, String)>`

error[E0308]: mismatched types
  --> src/main.rs:29:33
   |
29 | async fn index(web::Path((code, datetime)): web::Path<(String, String)>) -> impl Responder {
   |                -----------------^^^^^^^^--
   |                |                |
   |                |                expected struct `String`, found struct `time_and_sales_deliver::schema::stocks::datetime`
   |                this expression has type `actix_web::web::Path<(String, String)>`

error[E0277]: `time_and_sales_deliver::schema::stocks::code` doesn't implement `std::fmt::Display`
  --> src/main.rs:31:57
   |
31 |     format!("{{\"code\":\"{}\", \"datetime\":\"{}\"}}", code, datetime)
   |                                                         ^^^^ `time_and_sales_deliver::schema::stocks::code` cannot be formatted with the default formatter
   |
   = help: the trait `std::fmt::Display` is not implemented for `time_and_sales_deliver::schema::stocks::code`
   = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
   = note: this error originates in the macro `$crate::__export::format_args` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: `time_and_sales_deliver::schema::stocks::datetime` doesn't implement `std::fmt::Display`
  --> src/main.rs:31:63
   |
31 |     format!("{{\"code\":\"{}\", \"datetime\":\"{}\"}}", code, datetime)
   |                                                               ^^^^^^^^ `time_and_sales_deliver::schema::stocks::datetime` cannot be formatted with the default formatter
   |
   = help: the trait `std::fmt::Display` is not implemented for `time_and_sales_deliver::schema::stocks::datetime`
   = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
   = note: this error originates in the macro `$crate::__export::format_args` (in Nightly builds, run with -Z macro-backtrace for more info)

Some errors have detailed explanations: E0277, E0308, E0433, E0599, E0605.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `time_and_sales_deliver` due to 8 previous errors

(C) 2020 dogwood008 禁無断転載 不許複製 Reprinting, reproducing are prohibited.