Questions tagged [rust-actix]

Actix is a rust library built on the Actor Model which allows applications to be written as a group of independently executing but cooperating "Actors" which communicate via messages.

Actix (source code) is a Rust actors framework.

233 questions
2
votes
1 answer

How can I pass query string to HttpRequest.url_for() in actix-web?

Documentation about url_for. Code: fn index(req: HttpRequest) -> HttpResponse { let url = req.url_for("foo", &["1", "2", "3"]); // <- generate url for "foo" resource HTTPOk.into() } fn main() { let app = Application::new() …
Alex
  • 51
  • 4
2
votes
0 answers

How to build an Actix Web TestServer with state and a factory?

In the actix-web documentation, there are two examples on how to build a TestServer with either a factory function: use actix_web::{http, test, App, HttpRequest, HttpResponse}; // ... fn main() { let mut srv =…
trolle3000
  • 1,067
  • 2
  • 14
  • 27
2
votes
0 answers

Closure vs. function declaration in struct

I'm having trouble (as a newbie) getting my application to compile. This is likely the most obvious detail but I'm struggling with comprehending what's happening. I'm writing a wrapper struct for the Actix Web server library. My struct is defined as…
ddibiase
  • 1,412
  • 1
  • 20
  • 44
2
votes
1 answer

Embedding actix-web into a struct so that I can start/stop server

I'm working on embedding actix-web into a binding library. I would like to declare a HttpServer within a struct so that I can easily call .start() and .system_exit(). From my very basic reading of the source code it's already implemented as a struct…
ddibiase
  • 1,412
  • 1
  • 20
  • 44
2
votes
1 answer

What does the "R + 'static" syntax mean in "F: FnOnce(&mut Resource) -> R + 'static"?

I am trying to understand the following code in actix-web pub fn resource(self, path: &str, f: F) -> App where F: FnOnce(&mut Resource) -> R + 'static, From my understanding, resource is a function that takes 2 parameters: a string…
user10714010
  • 865
  • 2
  • 13
  • 20
2
votes
1 answer

Why does map and map_err capture the same variable?

I'm building a chained future ActorFuture, Error = Vec, Actor = Self> On success it will have vector of string outputs of all futures chained with .and_then. On first error processing will stop, and I want to return…
tworec
  • 4,409
  • 2
  • 29
  • 34
2
votes
1 answer

Use precomputed big object in actix-web route handler

Is there a way to make an actix-web route handler aware of a pre-computed heavy object, that is needed for the computation of result? What I intend to do, in the end, is to avoid having to recompute my_big_heavy_object each time a request comes…
Jivan
  • 21,522
  • 15
  • 80
  • 131
1
vote
1 answer

expected `()`, found `Result, _>` using midleware in actix_web trying to return Ok

I'm trying to accomplish a very simple task here. I don't understand why it has become so complex. I'm attempting to modify headers before they reach the service and return a failure if a certain condition is not met. Here is my middleware file: use…
user63898
  • 29,839
  • 85
  • 272
  • 514
1
vote
2 answers

rust yew app working on local laptop/pc not behind nginx

This is prob very easy to solve(I hope) I never deployed wasm apps before and now I have a working frontend(rust yew) and backend(actix) working locally on my laptop and PC when I run it without nginx, just raw dev. Problem comes when I…
rek2
  • 101
  • 12
1
vote
0 answers

How to properly validate actix web headers (rust)?

I am fairly new to rust so trying to find the proper way to handle this specific use case. We are using actix web server and have created a route which maps to the following function: #[derive(serde::Deserialize, serde::Serialize, Debug)] pub struct…
1
vote
2 answers

Dedup logic without getting "cannot return value referencing local variable `queues` returns a value referencing data owned by the current function"

I have the following structs: use std::sync::Mutex; pub struct Message { id: String, content: String, last_read: Option, uuid: String, } impl Message { pub fn get_uuid(&self) -> String { self.uuid.to_owned() …
dvr
  • 370
  • 1
  • 9
1
vote
2 answers

How to register all services under the crate "service" in Actix Web

I have a crate 'services' with all services for the App Here's an example of one of the services, using the #[get("/orders")] macro for routing #[get("/orders")] pub async fn fetch_orders(state: Data) -> impl Responder { let db:…
1
vote
1 answer

Sea Orm - Actix , vote system

Django user here. I switching to Actix written in rust. How to add or subtract 1 from existed value in database. I have function post.vote = ActiveValue::Set(post.vote.into_wrapped_value() + 1); and also tried post.vote =…
DoDr
  • 85
  • 7
1
vote
1 answer

what is the correct way of implementing auth in actix_web?

I've been doing rust for just short while but didn't much struggle until this issue. I want to authenticate each request, and make returned value (from auth service) available inside requests. I've read implementing FromRequest for the struct…
dzCodes
  • 25
  • 6
1
vote
1 answer

Getting error "expected function" when trying to call function from a unit test

I'm trying to write a simple unit test case for an Actix web function, however I'm getting an error when trying to call the function from the test function. The error I'm getting is: E0618: expected function, found I've tried…
Pavel Byles
  • 21
  • 1
  • 6