1 unstable release

0.2.3 May 12, 2023
0.2.2 May 12, 2023
0.1.11 Apr 8, 2023
0.1.9 Feb 27, 2023

#275 in HTTP server

Download history 4/week @ 2024-02-25 192/week @ 2024-03-31

192 downloads per month

MIT/Apache

77KB
1.5K SLoC

wscml

介绍

rust编写web server服务 web server cml。因为还是测试版本,每发布一个版本前一个版本就将关闭使用。直到完成测试版本,正式版将由1.0版本以后。 rust: web server web server cml。Because or the test version, each release a version will be closed using the previous version. Until he finished test version, after the official version by version 1.0.

软件架构

软件架构说明 Software architecture description

官方网站

http://www.qhd.in

QQ群:300021630

升级内容

新增tokio多线程方法 New tokio multi-thread method 优化tokio多线程方法 Tokio multithreading optimization method

使用说明

Cargo.toml

wscml = "0.2"

main.rs

use wscml::{CmlServer,PortR,Hshell,pr_time};

fn main(){
    let mut cml = CmlServer::new("0.0.0.0:8080",1000);
    cml.http_setbpost("0.0.0.0:8000");
    cml.templ("{$".to_string(),"}".to_string()); //模板的替换模板
    cml.http_route( "/", index,"");
    cml.http_route( "/sleep?user&name", sleep,"get|post");
    cml.http_route( "/sleeps?id&code", sleeps,"get");
    cml.http_route( "/post?id&mm", post,"get");
    cml.biud();
    
}

fn index (r: PortR, h:Hshell) -> String {
    println!("    index:{:?}",r);
    format!("")
}

fn sleeps (r: PortR, h:Hshell) -> String {

    let sc = r.getg_n("user");
    let name: String = r.getg_n("name");
    let zt: String = r.getreqtop("state");
    let zts: String = r.getreqtop("methods");
    let body: String = format!(
        "
            <head>
            <title>{}</title>
            <meta name=\"keywords\" content=\"{}\">
            <meta name=\"subject-time\" content={:?}>
            <meta name=\"description\" content=\"\">
            <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1, viewport-fit=cover\">
            <meta name=\"format-detection\" content=\"telephone=no\">
            </head>
        ",
        "陈孟蕾 - 个人中心 - 华陈数据",
        "华陈数据开发者社区,云计算社区,云+社区,开发者技术分享社区,www.qhd.in",
        pr_time("%Y-%m-%d %H:%M:%S"),
    );

    let a: String = format!(
        "<html>{}<body><p>按钮</p>user:{} </br> name:{} </br> 状态:{} </br> 方法:{}</body></html>",
        body,
        sc,
        name,
        zt,
        zts
    );
    a
}

fn sleep (r: PortR,mut h:Hshell) -> String {
    println!("{:?}",r);

    let tem: String = h
        .add("name","野原新之助")
        .add("pname","sss")
        .template("h/yyxzz.html");
    tem
}

fn post (r: PortR, h:Hshell) -> String {
    format!("post")
}

tokio 使用方法

Cargo.toml

tokio = { version = "1", features = ["full"] }
wscml = "0.2"

main.rs

use wscml::{TCmlServer,PortR,Hshell,pr_time};

#[tokio::main]
async fn main(){

    let mut cml = TCmlServer::new("0.0.0.0:8080").await;
    cml.templ("{$".to_string(),"}".to_string()).await;
    cml.http_route( "/", index,"").await;
    cml.http_route( "/sleep?user&name", sleep,"get|post").await;
    cml.http_route( "/sleeps?id&code", sleeps,"get").await;
    cml.http_route( "/post?id&mm", post,"get").await;
    cml.biud().await;
    
}

fn index (r: PortR, h:Hshell) -> String {
    println!("    index:{:?}",r);
    format!("")
}

fn sleeps (r: PortR, h:Hshell) -> String {

    let sc = r.getg_n("user");
    let name: String = r.getg_n("name");
    let zt: String = r.getreqtop("state");
    let zts: String = r.getreqtop("methods");
    let body: String = format!(
        "
            <head>
            <title>{}</title>
            <meta name=\"keywords\" content=\"{}\">
            <meta name=\"subject-time\" content={:?}>
            <meta name=\"description\" content=\"\">
            <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1, viewport-fit=cover\">
            <meta name=\"format-detection\" content=\"telephone=no\">
            </head>
        ",
        "陈孟蕾 - 个人中心 - 华陈数据",
        "华陈数据开发者社区,云计算社区,云+社区,开发者技术分享社区,www.qhd.in",
        pr_time("%Y-%m-%d %H:%M:%S"),
    );

    let a: String = format!(
        "<html>{}<body><p>按钮</p>user:{} </br> name:{} </br> 状态:{} </br> 方法:{}</body></html>",
        body,
        sc,
        name,
        zt,
        zts
    );
    a
}

fn sleep (r: PortR,mut h:Hshell) -> String {
    println!("{:?}",r);

    let tem: String = h
        .add("name","野原新之助")
        .add("pname","sss")
        .template("h/yyxzz.html");
    tem
}

fn post (r: PortR, h:Hshell) -> String {
    format!("post")
}

参与贡献

  1. 陈孟蕾

Dependencies

~7–16MB
~158K SLoC