我对 Rust 还很陌生,所以这可能是一个简单的问题。
我正在尝试为处理程序创建一个小型注册表,该注册表应返回实现该TransferObject特征的任何结构:
pub trait TransferObject: Hash + PartialEq {}
Run Code Online (Sandbox Code Playgroud)
HashMap由于我存储在Trait中注册的处理程序,因此需要Hash和PartialEq作为 Supertraits:
pub struct RequestHandlerRegistry {
handlers: HashMap<RequestMethod, HashMap<String, RequestHandler<dyn TransferObject>>>,
}
Run Code Online (Sandbox Code Playgroud)
但在结构中,我收到错误,因为使用了参数,TransferObject所以无法将其制成对象。我已经尝试过做这样的事情:PartialEqSelf
pub struct RequestHandlerRegistry {
handlers: HashMap<RequestMethod, HashMap<String, RequestHandler<Box<dyn TransferObject>>>>,
}
Run Code Online (Sandbox Code Playgroud)
但我仍然遇到同样的错误。
有什么办法可以解决这个问题吗?
我还创建了一个Playground来轻松重现错误。
这些是我从 API ( /login) 返回的标头:
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 354
Content-Type: application/json; charset=utf-8
Date: Sun, 21 Mar 2021 19:34:19 GMT
ETag: W/"162-9yg5khk3mdMK+w5SIteR+26LIrw"
Keep-Alive: timeout=5
Set-Cookie: refresh_token=<INSERT REFRESH_TOKEN HERE>; Max-Age=2592000; Expires=Tue, 20 Apr 2021 19:34:19 GMT; HttpOnly
X-Powered-By: Express
Run Code Online (Sandbox Code Playgroud)
这是 Express 后端的代码:
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 354
Content-Type: application/json; charset=utf-8
Date: Sun, 21 Mar 2021 19:34:19 GMT
ETag: W/"162-9yg5khk3mdMK+w5SIteR+26LIrw"
Keep-Alive: timeout=5
Set-Cookie: refresh_token=<INSERT REFRESH_TOKEN HERE>; Max-Age=2592000; Expires=Tue, 20 Apr 2021 19:34:19 …Run Code Online (Sandbox Code Playgroud) google-chrome web-development-server node.js express next.js