我正在尝试使用Rocket构建一个简单的HTTP服务器,从外部数据库加载数据。每个端点都将提供启动服务器时加载的数据集的过滤和排序子集。
这很好,因为我可以传递net stat -anp | grep portnumber
。
Vec<Media>
但是,当我想将向量迭代到#![feature(plugin)]
#![plugin(rocket_codegen)]
extern crate rusted_cypher;
extern crate rocket;
#[macro_use]
extern crate rocket_contrib;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
use std::fmt::Debug;
use rusted_cypher::GraphClient;
use rocket_contrib::{JSON, Value};
use rocket::State;
// this works
#[get("/")]
fn index(data: State<Vec<Media>>) -> JSON<Value> {
JSON(json!(data.inner()))
}
fn loadData() -> Vec<Media> {
let graph = GraphClient::connect("http://server:7474/db/data").unwrap();
let results = graph.exec("MATCH (m:SIMPLEFIED) RETURN m").unwrap();
let mut data: Vec<Media> = Vec::new();
for row in results.rows() {
data.push(Media {
id: row.get("m.id").unwrap(),
rating: row.get("m.rating").unwrap(),
release_date: row.get("releaseDate").unwrap(),
});
}
data
}
#[derive(Debug, Serialize, Deserialize)]
struct Media {
id: String,
rating: u16,
release_date: i32,
}
fn main() {
rocket::ignite()
.manage(loadData())
.mount("/", routes![index])
.launch();
}
f
我收到此错误
错误[E0277]:不满足特征限制
// simple release date filter for release date greater than <d> #[get("/gt/<d>")] fn gt(d: i32, data: State<Vec<Media>>) -> JSON<Value> { let v = data.inner(); let out = v.iter() .filter(|m| m.release_date > d) .collect::<Vec<Media>>(); JSON(json!(out)) }
(...)
未实现特征
std::vec::Vec<Media>: std::iter::FromIterator<&Media>
`的std :: VEC :: VEC
和一些有用的说明
类型
的元素的迭代器std::iter::FromIterator<&Media>
的集合无法从中构建 类型为std::vec::Vec<Media>