小编Pio*_*zek的帖子

如何将许多参数传递给 rust actix_web 路由

是否可以将多个参数传递到 axtic_web 路由中?

// srv.rs (frag.)

HttpServer::new(|| {
  App::new()
    .route(
      "/api/ext/{name}/set/config/{id}",
      web::get().to(api::router::setExtConfig),
    )
})
.start();
Run Code Online (Sandbox Code Playgroud)
// router.rs (frag.)

pub fn setExtConfig(
    name: web::Path<String>,
    id: web::Path<String>,
    _req: HttpRequest,
) -> HttpResponse {
  println!("{} {}", name, id);
  HttpResponse::Ok()
      .content_type("text/html")
      .body("OK")
}
Run Code Online (Sandbox Code Playgroud)

对于只有一个参数的路由,一切正常,但对于本示例,我在浏览器中仅看到消息:wrong number of parameters: 2 expected 1,响应状态代码为 404。

我确实需要传递更多参数(从一个到三个或四个)......

rust actix-web

13
推荐指数
1
解决办法
3922
查看次数

单选模式下的Vuetify数据表,选择一行选择所有其他行

我正在尝试选择表中的一行并发出所选项目。

选择一个将选择所有对象,但仅将第一个遇到的对象保存到模型中(作为selected变量)。

你有什么想法吗,我做错了什么?

在此输入图像描述

<template>
  <v-data-table
    :headers="headers"
    :items="items"
    :search="search"
    :loading="loading"
    v-model="selected"
    single-select
    show-select
    :options="{itemsPerPage:5}"
    @item-selected="itemSelected"
  >
    <template v-slot:top>
      <v-toolbar flat>
        <v-text-field
          v-model="search"
          append-icon="mdi-magnify"
          label="Search"
          single-line
          hide-details
        ></v-text-field>
      </v-toolbar>
    </template>

    <template v-slot:item.name="{ item }">{{ item.name }}</template>
  </v-data-table>
</template>

<script>
export default {
  name: "variable-selector",
  props: ["variables", "map", "index"],
  data() {
    return {
      search: "",
      selected: {},
      loading: false,
      items: [],
      headers: [{ text: "Variable name", value: "name", sortable: true }]
    };
  },
  methods: {
    itemSelected(selection) {
      if (selection.value) {
        this.$emit("selected", …
Run Code Online (Sandbox Code Playgroud)

datatable select vue.js vuetify.js

7
推荐指数
1
解决办法
5898
查看次数

如何从 actix_web::HttpRequest 获取(二进制)有效负载

我正在用 Rust 编写一些 Web api。我使用 XMLHttpRequest 从 JavaScript 发送 Unit8Array,我需要在服务器中以字节形式读取它们。

我的服务方式声明是:

pub fn user_login_bin(mut req: HttpRequest) {
 println!("{:?}", req);
 let mut stream = req.take_payload().take();

 // error label: method not found in `actix_http::payload::Payload<()>`
 let item = stream.poll().unwrap(); 

 println!("{:?}", item);

 HttpResponse::Ok().into()
}
Run Code Online (Sandbox Code Playgroud)

我如何从 actix_web::HttpRequest 有效负载读取 Vec ?

我尝试了一些示例代码,但它也不起作用:

 req.take_payload()
    // error label: method (fold) not found in `actix_http::payload::Payload<()>`
    .fold(BytesMut::new(), move |mut body, chunk| {
        body.extend_from_slice(&chunk);
        Ok::<_, Error>(body)
    })
    .and_then(|bytes| {
        println!("request body: {:?}", bytes);
    });
Run Code Online (Sandbox Code Playgroud)

httprequest payload rust actix-web

6
推荐指数
1
解决办法
2197
查看次数

如何使用另一个目录中的模块?

我有一个 Rust 项目,其结构如下:

\n\n
.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Cargo.lock\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Cargo.toml\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 src\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 routes\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 mod.rs\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 router_get.rs\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 router_post.rs\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 main.rs\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 server.rs\n
Run Code Online (Sandbox Code Playgroud)\n\n

我需要使用中的路由模块server.rs,但是当我尝试编译它时,它给了我一个错误:

\n\n
error[E0432]: unresolved import `super::routes`\n  --> src/server.rs:10:5\n   |\n10 | use super::routes;\n   |     ^^^^^^^^^^ no `routes` in the root\n
Run Code Online (Sandbox Code Playgroud)\n\n

当我尝试使用routeswithmain.rsmod routes,一切正常。但我需要在server.rs.

\n\n

路线/mod.rs

\n\n
pub mod router_get;\npub mod router_post;\n
Run Code Online (Sandbox Code Playgroud)\n

module rust

5
推荐指数
1
解决办法
8126
查看次数