Build process is hanging when inserting a document

I am building a website using actix-web and mongodb crate v1.1.1. At first, I tested the driver for connecting to the database, get the collection handle, create and read form this collection. That test was in the main fn and it works. But, when adding the client and collection handles as an application state extractor the build process is hanging.

public_types.rs

main.rs

use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder};
use mongodb::bson::{self, doc, Bson};
use mongodb::error::Error;
use std::env;
use chrono::{DateTime, TimeZone, NaiveDateTime, Utc};
use futures::stream::{StreamExt, Next};
use std::sync::Arc;
use mongodb::Client;
use public_types::public_types::AppState;
mod routing;
mod public_types;

#[actix_web::main]
async fn main() → std::io::Result<()> {

// Load the MongoDB connection string from an environment variable:
let client_uri = “mongodb+srv://admin-zc:EeecOlo773bgzlY7@cluster0.mivex.mongodb.net/test?retryWrites=true&w=majority”;
// env::var(“MONGODB_URI”).expect(“You must set the MONGODB_URI environment var!”);
// A Client is needed to connect to MongoDB:
let client = mongodb::Client::with_uri_str(client_uri.as_ref()).await;
let client = client.unwrap();
let reservation_collection = client.database(“zcdb”).collection(“reserveation”);

let data = AppState {
client: Arc::new(client),
reservation_col: Arc::new(reservation_collection),
};

HttpServer::new(move || {
App::new()
.data(data.clone())
.configure(routing::routing::home_routing)
.configure(routing::routing::book_routing)
.configure(routing::routing::query_routing)
.configure(routing::routing::login_routing)
})
.bind(“127.0.0.1:8080”)?
.run()
.await
}

Hi @Ahmed_Yasen

This is a known issue with rustc 1.45-1.47. (I had problems with this myself!) You can fix it by either pinning your Rust version to 1.44, or upgrading to 1.48+.

If you need to pin to an older release of rust (rather than just upgrading and using the latest version) and you’re using rustup, you can set it for your project by running rustup override set 1.44 in your project directory.

Hope this helps!

3 Likes