我是生锈的新手,我正在尝试用HTML构建一个简单的网页。
这是我的密码:
use rocket::*;
use rocket::response::content::Html;
#[get("/")]
fn index() -> content::Html<&'static str> {
content::Html(r#"
<title>GCD Calculator</title>
<form action="/gcd" method="post">
<input type="text" name="n" />
<input type="text" name="n" />
<button type="submit">Compute GCD</button>
</form>
"#)
}
#[launch]
fn rocket()->_{
rocket::build().mount("/", routes![index])
}但是它返回错误:
Compiling hello-rocket v0.1.0 (/home/garuda/dev/Rust/Rocket/hello-rocket)
error[E0432]: unresolved import `rocket::response::content::Html`
--> src/main.rs:2:5
|
2 | use rocket::response::content::Html;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `Html` in `response::content`
error[E0433]: failed to resolve: use of undeclared crate or module `content`
--> src/main.rs:5:15
|
5 | fn index() -> content::Html<&'static str> {
| ^^^^^^^ use of undeclared crate or module `content`
error[E0433]: failed to resolve: use of undeclared crate or module `content`
--> src/main.rs:6:5
|
6 | content::Html(r#"
| ^^^^^^^ use of undeclared crate or module `content`
Some errors have detailed explanations: E0432, E0433.
For more information about an error, try `rustc --explain E0432`.
error: could not compile `hello-rocket` due to 3 previous errors我确信这个模块的存在是因为https://api.rocket.rs/v0.4/rocket/response/content/struct.Html.html
发布于 2022-06-29 06:08:53
发布于 2022-06-29 05:22:14
您可以使用完整的路径名来引用该模块,即。
#[get("/")]
fn index() -> rocket::response::content::Html<&'static str> {
rocket::response::content::Html(...)
}或将特定模块添加到当前命名空间中,使用
use rocket::response::content;在您的代码中,您只是使用use rocket::*在您的命名空间中添加火箭模块中的所有内容,用use::rocket::response::content::Html添加Html结构,所以您也可以直接使用Html:
fn index() -> Html<&'static str> {
Html(...)
}https://stackoverflow.com/questions/72795952
复制相似问题