Skip to content
This repository has been archived by the owner on May 10, 2020. It is now read-only.

Simple Example compling error "no method named for_each found for type" #86

Closed
c5soft opened this issue Nov 6, 2018 · 1 comment
Closed

Comments

@c5soft
Copy link

c5soft commented Nov 6, 2018

Simple Example source code from https://docs.rs/tiberius/0.3.1/tiberius/
//-----------------------------------------------------------------------------------------------
[
extern crate tiberius;
use futures::Future;
use futures_state_stream::StateStream;
use tokio::executor::current_thread;
use tiberius::SqlConnection;

fn main() {

// 1: for windows we demonstrate the hardcoded variant
// which is equivalent to:
//     let conn_str = "server=tcp:localhost,1433;integratedSecurity=true;";
//     let future = SqlConnection::connect(conn_str).and_then(|conn| {
// and for linux we use the connection string from an environment variable
let conn_str = if cfg!(windows) {
    "server=tcp:localhost,1433;integratedSecurity=true;".to_owned()
} else {
    ::std::env::var("TIBERIUS_TEST_CONNECTION_STRING").unwrap()
};

let future = SqlConnection::connect(conn_str.as_str())
    .and_then(|conn| {
        conn.simple_query("SELECT 1+2").for_each(|row| {
            let val: i32 = row.get(0);
            assert_eq!(val, 3i32);
            Ok(())
        })
    })
    .and_then(|conn| conn.simple_exec("create table #Temp(gg int);"))
    .and_then(|(_, conn)| conn.simple_exec("UPDATE #Temp SET gg=1 WHERE gg=1"));

current_thread::block_on_all(future).unwrap();

}
]
//-----------------------------------------------------------------------------------------------

it can not be compiled, it reported "error[E0599]: no method named for_each found for type "

C:/Users/Administrator/.cargo/bin/cargo.exe run --package mssql --bin mssql
Compiling mssql v0.1.0 (D:\rust\mssql)
warning: use of deprecated item 'tokio::executor::current_thread': use tokio-current-thread crate or functions in tokio::runtime::current_thread instead
--> src\main.rs:7:5
|
7 | use tokio::executor::current_thread;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[warn(deprecated)] on by default

error[E0599]: no method named for_each found for type tiberius::stmt::QueryResult<tiberius::query::ResultSetStream<std::boxed::Box<dyn tiberius::BoxableIo>, tiberius::query::QueryStream<std::boxed::Box<dyn tiberius::BoxableIo>>>> in the current scope
--> src\main.rs:25:45
|
25 | conn.simple_query("SELECT 1+2").for_each(|row| {
| ^^^^^^^^
|
= note: the method for_each exists but the following trait bounds were not satisfied:
&mut tiberius::stmt::QueryResult<tiberius::query::ResultSetStream<std::boxed::Box<dyn tiberius::BoxableIo>, tiberius::query::QueryStream<std::boxed::Box<dyn tiberius::BoxableIo>>>> : futures_state_stream::StateStream
&mut tiberius::stmt::QueryResult<tiberius::query::ResultSetStream<std::boxed::Box<dyn tiberius::BoxableIo>, tiberius::query::QueryStream<std::boxed::Box<dyn tiberius::BoxableIo>>>> : std::iter::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:
|
5 | use futures_state_stream::StateStream;
|

error: aborting due to previous error

For more information about this error, try rustc --explain E0599.
error: Could not compile mssql.

To learn more, run the command again with --verbose.

Process finished with exit code 101

@c5soft
Copy link
Author

c5soft commented Nov 6, 2018

with futures-state-stream="0.1.0" it works.

[dependencies]
chrono = "0.4.6"
futures="0.1.25"
futures-state-stream="0.1.0"
tokio="0.1.11"
tiberius = { version = "0.3.1", default-features=false,features=["chrono"] }

@c5soft c5soft closed this as completed Nov 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant