Questions tagged [rust-rocket]

A Rust web framework that uses unstable nightly features to provide a highly ergonomic and type-safe experience.

Rocket is a web framework for Rust that makes it simple to write fast web applications without sacrificing flexibility or type safety. All with minimal code.

Useful links

281 questions
4
votes
1 answer

Passing a non-static lifetime to Rocket's manage

How can I pass an object with a non-static lifetime to Rocket's manage? Currently I have something along these lines: fn foo<'a>(bar: Bar<'a>) -> Result<(), Error> { rocket::ignite() .manage(bar) .mount("/", routes![index]) …
Will Squire
  • 6,127
  • 7
  • 45
  • 57
4
votes
1 answer

I want to start Rocket in a module out of `main()` but failed

I want to start Rocket in a module out of main(), thus can simplify main() but I failed. I modified the Quicktart from rocket The code: mod myRocket { #![feature(plugin)] #![plugin(rocket_codegen)] extern crate rocket; #[get("/")] …
llxxbb
  • 1,241
  • 1
  • 10
  • 16
4
votes
1 answer

Lifetimes when Deserializing JSON within a FromForm

I'm having trouble understanding the relationship between the lifetimes on this code. Basically, I have a Rocket API that receives some x-www-form-urlencoded data, with only one key: json. This key contains, intuitively, a JSON value, encoded with…
4
votes
1 answer

Unresolved import Template when building Rocket handlebars example

I am unable to get the Rocket handlebars example to work. These are my Cargo.toml dependencies: [dependencies] rocket = "*" rocket_codegen = "*" rocket_contrib = "*" serde = "*" serde_json = "*" serde_derive = "*" The errors: error[E0432]:…
Kian
  • 695
  • 2
  • 11
  • 23
3
votes
1 answer

Inserting a struct into an sqlite db using sqlx and rust

I have a question regarding inserting a data structure into a db and I can't seem to find any documentation on. I have a data structure #[derive(FromRow, Getters, Default, Serialize, Deserialize, Debug)] #[serde(crate =…
RuboGubo
  • 35
  • 5
3
votes
2 answers

Rust how to select if table row exists in diesel?

My goal is to query the database and find if a user already exists with the giving email. Looking at the documentation, this appears the way to do so. The only difference is I want to query based on the email instead of the name of the user. I have…
Cedric Martens
  • 1,139
  • 10
  • 23
3
votes
1 answer

Migrating from rocket 0.4 to rocket 0.5 with sync_db_pools: How to return the query results sync?

I am trying to migrate an application from rocket 0.4 to rocket 0.5 Before it was using rocket_contrib feature diesel_postgres_pool and I though rocket_sync_db_pools would be the best fit for migration (but I am open to alternatives here) I tried to…
Alex
  • 32,506
  • 16
  • 106
  • 171
3
votes
1 answer

Testing with Rocket and Diesel

I am trying to work on a web app with Diesel and Rocket, by following the rocket guide. I have not able to understand how to do testing of this app. //in main.rs #[database("my_db")] struct PgDbConn(diesel::PgConnection); #[post("/users",…
CeNiEi
  • 97
  • 1
  • 5
3
votes
1 answer

Post Rocket route is forwarded (Rust)

Sorry to ask such a basic question, there's little info about this in Stack Overflow and GitHub. This must be something silly, but I'm not getting it. I'm trying to send via JavaScript's fetch to a Rust post endpoint with Rocket 0.5 RC1. But I'm…
Jose A
  • 10,053
  • 11
  • 75
  • 108
3
votes
2 answers

How do I use print! with Rocket when compiling for release?

I've got some route handlers with print!() statements in it. They work just fine when I compile my app for debug. However, when compiling for release, Rocket appears to be "muting" all the print statements (as well as logging functions from log…
keddad
  • 1,398
  • 3
  • 14
  • 35
3
votes
1 answer

Issue trying to set up Rocket server with a Mongodb pool

I'm switching from Nodejs with NestJs to Rust Rocket + juniper. Even if I start feeling confident in Rust i'm having difficulties with some simple thing. I'm trying to create a mongdb pool to attach to my app but I'm having some issue. Here is my…
user1445685
  • 793
  • 1
  • 11
  • 25
3
votes
1 answer

How to use rocket on stable release of Rust

I am trying to use stable version of rustc to compile a rocket web application. rocket crate compiles fine but I would like to use a static file server from rocket_contrib. My Cargo.toml file looks like this: [dependencies] rocket =…
3
votes
1 answer

How to post JSON data in rocket 0.5.0-rc.1?

I am trying to build a POST handler, that receives JSON data with rocket (version: 0.5.0-rc.1). This is the code I wrote: use rocket::{post, response::content, routes, serde::{Deserialize, Serialize}}; #[derive(Debug, Deserialize, Serialize,…
frankenapps
  • 5,800
  • 6
  • 28
  • 69
3
votes
1 answer

the trait `Serialize` is not implemented for <'_>

#[derive(serde::Serialize)] struct IndexLink<'r>{ text: &'r str, link: &'r str; } #[derive(serde::Serialize)] struct IndexContext<'r> { title: &'r str, links: Vec<&'r IndexLink<&'r>> } #[get("/")] pub fn index() -> Template { …
cactus
  • 357
  • 4
  • 16
3
votes
1 answer

Why "no method named `execute` found" when using diesel::insert_into?

I have a problem when I use diesel::insert_into to insert data into the database: table! { post (id) { id -> Integer, username -> Varchar, postdata -> Varchar, } } pub fn create_new_post(post: Post, conn: DbConn) { …
awbt
  • 41
  • 2
1 2
3
18 19