Skip to content
Rob Ede edited this page Feb 25, 2022 · 20 revisions

Where can I see examples of project structure?

The examples repo (https://github.com/actix/examples) projects and links to community samples in readme.

What is the MSRV policy of Actix Web?

Our MSRV policy is that we will support at least all Rust versions released in the last 6 months. I.e., the MSRV may be bumped in a minor release.

How can I return App from a function / why is AppEntry private?

App is a complex type and not intended to be returned from a function directly. The App::configure method provides a way to move routing setup to a shared function. In rare cases, a simple macro can be used for App setup. References: #780 #1005 #1156 #2039 #2073 #2082 #2301

(TODO: This is be possible in Actix Web v4.)

How do I use async/await inside a WebSocket handler?

struct StreamActor;
impl Actor for StreamActor {
    type Context = Context<Self>;
}

struct StreamMessage(String);
impl Message for StreamMessage {
    type Result = ();
}

impl StreamHandler<StreamMessage> for StreamActor {
    fn handle(&mut self, item: StreamMessage, ctx: &mut Context<Self>) {
        let future = async move {
            // await things in here
            println!("We got message {}", item.0);
        };

        // Context::spawn or Context::wait
        future.into_actor(self).spawn(ctx);
    }
}

[awc] How can I increase the payload limit for response bodies?

#[actix_rt::main]
async fn main() -> std::io::Result<()> {
    let res = awc::Client::new()
        .get("https://crates.io")
        .content_type("application/json")
        .send()
        .await
        .unwrap()
        .json::<HashMap<String, String>>()
        .limit(65535 * 128)
        .await
        .unwrap();

    Ok(())
}
Clone this wiki locally