println!("hiiiiiiiii");
//connect to database
let url = "mysql://root:password@localhost:3306/testDB";
let pool: Pool = Pool::new(url)?;
let mut conn: PooledConn = pool.get_conn()?;
//excel
let mut excel: Xlsx<_> = open_workbook("temperature.xlsx").unwrap();
// Let's create a table for payments.
conn.query_drop(
r"CREATE TABLE payment (
label text,
value int not null
)")?;
if let Some(Ok(r)) = excel.worksheet_range("Sheet1")
{
for row in r.rows(){
let k:String= (&row[0]).to_string();
let m:String= (&row[1]).to_string();
// println!("{}",k);
// println!("{}",m);
let payments = vec![
Payment { label: Some(k), value: Some(m) },
];
// Now let's insert payments to the database
conn.exec_batch(
r"INSERT INTO payment (label, value)
VALUES (:label, :value)",
payments.iter().map(|p| params! {
"label" => &p.label,
"value" => &p.value,
})
)?;
}
}
println!("Yay!");
Ok(())
}
#[tokio::main]
async fn main() {
// let hello1 = warp::path!("hello")
// .map(|| StatusCode::OK);
// let hello = hello1
// .with(warp::cors().allow_any_origin());
// warp::serve(hello).run(([127, 0, 0, 1], 8000)).await;
let hello = warp::get();
warp::serve(hello).run(([127, 0, 0, 1], 3030)).await;
error[E0277]: the trait bound (): Reply is not satisfied
--> src/main.rs:76:17
|
76 | warp::serve(hello).run(([127, 0, 0, 1], 3030)).await;
| ----------- ^^^^^ the trait Reply is not implemented for ()
| |
| required by a bound introduced by this call
|
= help: the trait Reply is implemented for (T,)
note: required by a bound in serve
--> /home/rohit/.cargo/registry/src/github.com-1ecc6299db9ec823/warp-0.3.2/src/server.rs:26:17
|
26 | F::Extract: Reply,
| ^^^^^ required by this bound in serve
error[E0277]: the trait bound (): Reply is not satisfied
--> src/main.rs:76:5
|
76 | warp::serve(hello).run(([127, 0, 0, 1], 3030)).await;
| ^^^^^^^^^^^^^^^^^^ --- required by a bound introduced by this call
| |
| the trait Reply is not implemented for ()
|
= help: the trait Reply is implemented for (T,)
note: required by a bound in warp::Server::<F>::run
--> /home/rohit/.cargo/registry/src/github.com-1ecc6299db9ec823/warp-0.3.2/src/server.rs:127:35
|
127 | <F::Future as TryFuture>: Reply,
| ^^^^^ required by this bound in warp::Server::<F>::run
warning: unused import: warp::Filter
--> src/main.rs:5:5
|
5 | use warp::Filter;
| ^^^^^^^^^^^^
|
= note: #[warn(unused_imports)] on by default
For more information about this error, try rustc --explain E0277.
warning: warp_tokio_rust_api (bin "warp_tokio_rust_api") generated 1 warning
error: could not compile warp_tokio_rust_api due to 2 previous errors; 1 warning emitted
println!("hiiiiiiiii");
//connect to database
let url = "mysql://root:password@localhost:3306/testDB";
let pool: Pool = Pool::new(url)?;
let mut conn: PooledConn = pool.get_conn()?;
//excel
let mut excel: Xlsx<_> = open_workbook("temperature.xlsx").unwrap();
// Let's create a table for payments.
conn.query_drop(
r"CREATE TABLE payment (
label text,
value int not null
)")?;
if let Some(Ok(r)) = excel.worksheet_range("Sheet1")
{
for row in r.rows(){
let k:String= (&row[0]).to_string();
let m:String= (&row[1]).to_string();
// println!("{}",k);
// println!("{}",m);
let payments = vec![
Payment { label: Some(k), value: Some(m) },
];
// Now let's insert payments to the database
conn.exec_batch(
r"INSERT INTO payment (label, value)
VALUES (:label, :value)",
payments.iter().map(|p| params! {
"label" => &p.label,
"value" => &p.value,
})
)?;
}
}
println!("Yay!");
Ok(())
}
#[tokio::main]
async fn main() {
let hello = warp::get()
.and(warp::path("info"));
warp::serve(hello).run(([127, 0, 0, 1], 3030)).await;
warp::get returns a Filter implementer with Extract = (), whereas warp::serve needs a Filter implementer with Extract: Reply. That's the shallow explanation of your error. You need something besides just warp::get(), like warp::any().map(|| ...)or something.
I'm not a warp expert and it's not clear to me what you're actually trying to do; e.g. what your hello function (which is shadowed by your local hello variable) is for. So it's hard to give any concrete advice.
Not yet. In order to help, we need to understand both:
What you want to do, and
How you have already tried to do it so far.
The source code you’ve provided gives us lots of information about (2), but we still don’t know anything about (1). For that, you’ll need to describe, in words, what you want your source code to do.
Your currently don't have any endpoints added to warp. You gave it the HTTP method and path, but haven't given it a function to handle the HTTP Request
If we look at this example from the warp docs, we can see what you're missing
let hi = warp::path("hello")
.and(warp::path::param())
.and(warp::header("user-agent"))
.map(|param: String, agent: String| {
format!("Hello {}, whose agent is {}", param, agent)
});
You don't need the header filter right now, but you do need to use map (or one of the other options) to actually handle the HTTP Request.
You should be able to add .map(hello) I think but it's been awhile since I used warp.