因此,我试图遵循的示例来构建一个简单的REST。半路上,锈蚀编译器给出了以下错误:unresolved imports 'rocket_contrib::Json', 'rocket_contrib::Value' no 'Json' in the root
我似乎搞不清我做错了什么。
这是我的Cargo.toml:
[package]
name = "rust-api-test"
version = "0.1.0"
authors = ["username"]
edition = "201
我正在尝试在Rocket Rust中创建一个表单来创建帖子(我还没有访问db )。当我尝试提交表单时,我得到了错误422。 错误: POST /new_post application/x-www-form-urlencoded:
=> Matched: POST /new_post (new_post_form)
=> Error: The incoming form failed to parse.
=> Outcome: Failure
=> Warning: Responding with 422 Unprocessable E
我已经使用rocket创建了一个服务器来访问ipfs URL的对等信息
程序如下所示
#[macro_use] extern crate rocket;
use rocket::local::asynchronous::Client;
use rocket::http::hyper::{Request, Response};
use std::collections::HashMap;
use rocket::futures::TryFutureExt;
use std::fmt::Error;
use serde_json::Value;
#[get("/")]
asy
我试着每晚安装Rust并编译Rocket的hello_world示例项目。我发现了一个错误:
error[E0599]: no associated item named `Lifetime`
error[E0599]: no associated item named `Lifetime` found for type `syntax::ast::GenericParam` in the current scope
--> /Users/azwar/.cargo/registry/src/github.com-1ecc6299db9ec823/rocket_codegen-0.3
我跟踪了quickstart guide。现在,我正在尝试返回一些超级简单的JSON,而文档是错误的,如果不使用IRC,就无法提交工单。 错误 error[E0432]: unresolved import `rocket::serde::json`
--> src/main.rs:2:20
|
2 | use rocket::serde::json::Json;
| ^^^^ could not find `json` in `serde`
For more information about this error, try `rus
我试图使用生锈柴油全文搜索,首先我添加了依赖项:
diesel_full_text_search = "1.0.1"
然后像这样调整我的搜索代码:
#[macro_use]
extern crate diesel;
use diesel::{QueryDsl, RunQueryDsl};
use diesel_full_text_search::{ to_tsvector};
use rust_wheel::config::db::config;
use diesel_full_text_search::TsVectorExtensions;
use crate::model
在Rust中通过Rocket返回Json最简单的方法是什么? #[post("/route", data = "<data>")]
fn route(someVariable: String) -> String {
// How can I return a json response here? {"a": "{someVariable}")
} 我尝试过:content::Json(),但它对我来说似乎太静态了。
我正在和火箭公司做一个锈蚀项目。我无法将一些模块正确导入到我的代码中。例如,我正在尝试导入“火箭::表单”。以下是我的cargo.toml文件和main.rs文件:
cargo.toml
[package]
name = "..."
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rocket = {
我是跟随学习火箭网络框架的锈。当我执行cargo run --verbose时,我会得到以下错误:
PS C:\Users\kin\Desktop\hello-rocket> cargo run --verbose
Updating registry `https://github.com/rust-lang/crates.io-index`
failed to parse registry's information for: serde
Caused by:
the given version requirement is invalid
系统细节
Desktop En
我希望测试我的应用程序的/signup端点。如果电子邮件已经存在,此端点将失败。我的考试第一次取得了成功,但在那之后就失败了。指示数据库正在保存响应。下面是我的代码:
#[macro_use] extern crate rocket;
use sqlx::mysql::MySqlPool;
use rocket::serde::{json::Json};
use rocket::response::status;
use rocket::http::Status;
use crate::schemas::Signup;
pub mod schemas;
#[cfg(test)] mod t
我一直试图为我的生锈构建创建一个Dockerfile,该文件允许我将应用程序与依赖项分开构建,如下面所示:
但是,这似乎不适合我,因为lib.rs文件有一个稍微不同的工作树。我的Dockerfile如下所示:
FROM rust:1.60 as build
# create a new empty shell project
RUN USER=root cargo new --bin rocket-example-pro
WORKDIR /rocket-example-pro
# create dummy lib.rs file to build dependencies separat
我想用生锈柴油过滤方法来添加这样的过滤条件:
#[macro_use]
extern crate diesel;
use crate::schema::dict::id;
mod schema;
mod models;
fn main() {
use crate::diesel::prelude::*;
use crate::schema::dict;
let query = dict.filter(id.gt(0));
}
这是dict表方案定义的:
table! {
dict (id) {
word -> Varchar,
phonetic
我是一个生锈编程的新手,我正在构建锈蚀+柴油+火箭框架。
当我运行命令cargo check或cargo run时,会发生以下错误:
The specified procedure could not be found. (os error 127)
--> src\main.rs:2:11
|
2 | #![plugin(rocket_codegen)]
操作系统: Windows 10
cargo.toml
[package]
name = "rest_in_rust"
version = "0.1.0"
authors = ["venka
我正在使用Rust和Rocket构建一个简单的REST。其中一个端点接受POST方法请求,并从请求体读取一个大字符串。我不知道怎么用火箭来做这个。
文档描述了如何从POST请求正文读取JSON对象,以及如何读取多部分表单数据,而不是原始字符串。有人知道怎么做吗?
更新:
按照戴夫下面的回答中的建议,我实现了FromDataSimple特性,以尝试解析请求体。这是我已经实现的,但是它只得到了一个"404 Not“响应:
struct Store {
contents: String,
}
impl FromDataSimple for Store {
type Err