我有以下代码:
extern crate futures; // 0.1.24
use futures::Future;
use std::io;
struct Context;
pub trait MyTrait {
fn receive(context: Context) -> Future<Item = (), Error = io::Error>;
}
pub struct MyStruct {
my_trait: MyTrait,
}
Run Code Online (Sandbox Code Playgroud)
当我尝试编译它时,我收到错误消息:
error[E0038]: the trait `MyTrait` cannot be made into an object
--> src/lib.rs:13:5
|
13 | my_trait: MyTrait,
| ^^^^^^^^^^^^^^^^^ the trait `MyTrait` cannot be made into an object
|
= note: method `receive` has no receiver
Run Code Online (Sandbox Code Playgroud)
我想我知道它为什么会发生,但我如何从结构中引用特征呢?可能吗?也许还有其他方法可以实现相同的行为?
是否有一些最佳实践如何在 Flask 中验证 json 请求?Flask restful 扩展中有一个有趣的方法,但我的应用程序中不需要它。我只想有这样的东西:
user_schema = {
'username': email,
'password': required,
'age': required
}
@app.route('new_user/', methods=['POST'])
def new_user():
validate_json(request.json, user_schema)
Run Code Online (Sandbox Code Playgroud) 我想创建一个页面来编辑一些用户数据,包括密码。如何使用Flask-Security在自己的视图中更改密码?