How to use html! macro?

How to use the html! macro in rust?

Please clarify a bit, what crate are you using?

I just know that there is a html macro. but I don't know to use which crate. My intension is to pass a database variable to a html textbox. Can you help me?

Is it possible to pass database values to html text box?

Well, what are you going to do with this textbox? Will it be rendered on static page, or included into the page generated by some other tool, or?..

Using Rocket framework i have called html file in the GET method and stored data in database in POST method.

Using Rocket framework i have called html file in the GET method and stored data in database in POST method.....

How to bind the inserted database values to the HTML text box? So, that if user re-enters data it will be updated.

What do you mean by "called html file"? Is it a prepared static page? If so, you might want to read about rocket templates - I'm on mobile and can't give an exact link, but check official site for details.

The html file is a prepared static page.But I don't know how to pass data from rust to html.I tried using rocket TEMPLATE , and I got a warning when i ran the code.

The rocket launched successfully , but due to the warning the TEMPLATE didn't work

Can you perhaps just show some code or even link to your project? Or a minified one that reproduces your problem?


I'll send you the whole code .....just go through it once.


  username VARCHAR NOT NULL,


table! {
    posts (id) {
        id -> Int4,
        username -> Varchar,
        pass -> Varchar,

use super::schema::*;

pub struct Post {
    pub id: i32,
    pub username: String,
    pub pass: String

pub struct NewPost<'a> {
    pub username: &'a str,
    pub pass: &'a str


extern crate diesel;
extern crate dotenv;

pub mod models;
pub mod schema;

use diesel::prelude::*;
use diesel::pg::PgConnection;
use dotenv::dotenv;
use std::env;
use self::models::{Post, NewPost};

pub fn establish_connection() -> PgConnection {

    let database_url = env::var("DATABASE_URL")
        .expect("DATABASE_URL must be set");
        .expect(&format!("Error connecting to {}", database_url))

pub fn create_post<'a>(conn: &PgConnection, username: &'a str, pass: &'a str) -> Post {
    use schema::posts;

    let new_post = NewPost {
        username: username,
        pass: pass,

        .expect("Error saving new post")


#![feature(proc_macro_hygiene, decl_macro)]

#[macro_use] extern crate rocket;
extern crate diesel;
extern crate display;
extern crate rocket_contrib;
extern crate serde;

use std::fs::File;
use rocket::request::Form;
use self::display::*;

struct User
username: String,
password: String,

fn index() -> File {
    File::open("hello.html").expect("File not found")

#[post("/", data = "<userdata>")]
fn login(userdata: Form<User>) 
let a=&userdata.username;
let b=&userdata.password;
let connection = establish_connection();
let post = create_post(&connection, a, b);

fn main() {
    rocket::ignite().mount("/", routes![index,login]).launch();


<!DOCTYPE html>
<meta charset="UTF-8">
<h1>Registration Form</h1>
<form method="POST">
<input type="text" name="username" placeholder="username"/>
<p><input type="password" name="password" placeholder="password" />
<p><button type="submit">submit</button>

I have provided you with all the code that I have written until now...!!!
Now I want you to help me to fetch data from DB to HTML text box.