This is the error I'm unable to call the method in main function
error[E0599]: no method named to found for reference &'static str in the current scope
--> src/main.rs:48:44
|
48 | .service(web::resource("/we".to(finally())))
| ^^ method not found in &'static str
main.rs
HttpServer::new(|| {
App::new()
// .service(web::resource("/roy").to(finally()))
.service(web::resource("/benstokes").to(will_win))
.service(web::resource("/we".to(finally())))
})
database2.rs
This file contains the database part and the data to be sent to html file using handlers
use std::fs;
use handlebars::{Handlebars, Renderable};
use sqlx::postgres::PgPoolOptions;
use serde_json::json;
use sqlx::Error;
use serde::Serialize;
#[derive(sqlx::FromRow)]
#[derive(Serialize)]
struct User {
title: String,
description: String,
name: String,
}
pub async fn one_final_page( users: Vec){
let mut handlebars = Handlebars::new();
let template_source = "templates/index1.hbs" ;
let template = handlebars::Template::compile(template_source);
let context = json!({
"users": users,
});
let html = handlebars.render_template(template_source, &context);
}
pub async fn finally() ->Result<(),Error>{
dotenv::dotenv().expect("Unable to load environment variables from .env file");
let db_url = std::env::var("DATABASE_URL").expect("Unable to read DATABASE_URL env var");
let mut pool = PgPoolOptions::new()
.max_connections(100)
.connect(&db_url)
.await.expect("Unable to connect to Postgres");
let query = sqlx::queryas::<, User>("SELECT title,description ,name FROM posts");
let users: Vec<User> = query.fetch_all(&pool).await?;
for user in &users {
println!("{}{}{}", user.title, user.description,user.name);
}
one_final_page(users).await;
Ok(())