Skip to content
Rob Ede edited this page Jul 21, 2020 · 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.

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