Struct df_web::web::Web

source ·
pub struct Web { /* private fields */ }

Implementations§

Examples found in repository?
examples/web.rs (line 33)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
fn main() {
    let mut root_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
    root_path = root_path.join("..");
    let conf_web_path = root_path.join("config");
    let conf_web_path = conf_web_path.join("web.json");

    let conf_web_path = conf_web_path.to_str().unwrap();
    let conf = match fs::read_to_string(conf_web_path) {
        Ok(content) => {
            if content == "" {
                object! {}
            } else {
                json::parse(content.as_str()).unwrap()
            }
        }
        Err(_) => {
            object! {}
        }
    };


    let public_path = root_path.join("df-web");
    let public_path = public_path.join("examples");
    let public_path = public_path.join("public");
    let public_path = public_path.to_str().unwrap();
    println!("http服务器启动 访问地址: {}", conf["url"].clone());
    println!("公共目录: {}", public_path.clone());
    Web::bind(conf["url"].as_str().unwrap(), public_path, conf["cors"].clone()).run(handle);

    fn handle(response: JsonValue) -> (JsonValue, i32, String) {
        println!("{:#}", response);
        let text = object! {"name":"2313",response:response};
        return (text, 200, "json".to_string());
    }
}

运行

Examples found in repository?
examples/web.rs (line 33)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
fn main() {
    let mut root_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
    root_path = root_path.join("..");
    let conf_web_path = root_path.join("config");
    let conf_web_path = conf_web_path.join("web.json");

    let conf_web_path = conf_web_path.to_str().unwrap();
    let conf = match fs::read_to_string(conf_web_path) {
        Ok(content) => {
            if content == "" {
                object! {}
            } else {
                json::parse(content.as_str()).unwrap()
            }
        }
        Err(_) => {
            object! {}
        }
    };


    let public_path = root_path.join("df-web");
    let public_path = public_path.join("examples");
    let public_path = public_path.join("public");
    let public_path = public_path.to_str().unwrap();
    println!("http服务器启动 访问地址: {}", conf["url"].clone());
    println!("公共目录: {}", public_path.clone());
    Web::bind(conf["url"].as_str().unwrap(), public_path, conf["cors"].clone()).run(handle);

    fn handle(response: JsonValue) -> (JsonValue, i32, String) {
        println!("{:#}", response);
        let text = object! {"name":"2313",response:response};
        return (text, 200, "json".to_string());
    }
}

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.