Skip to content
Rob Ede edited this page Jul 31, 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?

Not yet documented. See this test for how to return App.

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

Async behavior in actix handlers is less ergonomic than the standard async/await systems in Rust, but it is achiveable.

See this test file for more examples: https://github.com/actix/actix/blob/master/actix/tests/test_fut.rs

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(())
}