I am receiving an &str
from the application's args, but I need this value as &'static &str
. How can I convert it?
fn fun(var: &'static &str) {}
fn main() {
let var: &str = "temp";
fun(var);
}
error[E0308]: mismatched types
--> src/main.rs:102:9
|
102 | matches.value_of("STATIC-FILES").unwrap(),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected &str, found str
|
= note: expected type `&'static &str`
found type `&str`
error: aborting due to previous error
@more information
.
├── Cargo.lock
├── Cargo.toml
├── src
│ ├── main.rs
│ └── server.rs
// file: main.rs
extern crate clap;
use clap::{App, Arg};
mod server;
fn main() {
let app = App::new("My App")
.arg(
Arg::with_name("STATIC-FILES")
.help("Sets absolute path to client's static files")
.default_value("/var/www/client"),
)
let matches = app.get_matches();
let s = server::start(
matches.value_of("STATIC-FILES").unwrap(),
);
// file: server.rs
use actix_files as fs;
use actix_web::{guard, web, App, HttpResponse, HttpServer};
pub fn start(
static_files_path: &'static &str,
) -> io::Result<()> {
let sys = actix_rt::System::new("myappsvr");
HttpServer::new(move || {
let sfp = move || static_files_path;
App::new()
.service(fs::Files::new("/", sfp()).index_file("index.html"))
})
(...)
.start();
sys.run();
}
In main.rs
I am starting an HTTP server (Actix). The path to the directory with static files has to be passed as an argument.
App::new().service(fs::Files::new("/", sfp()).index_file("index.html"))
requires &'static &str
in place of sfp()
.