Why is there no implementation of Responder for i64? #2677
-
Hi frens, I'm struggling to work around an issue involving a #[derive(Default, Debug, Clone, Serialize, Deserialize, Responder)]
pub enum Error {
UserNotFound {
user: UserId
},
OperationNotPermitted {
user: UserId,
scope: Scope
}
// ---
}
#[derive(Default, Debug, Clone, Serialize, Deserialize, Responder)]
pub enum UserId {
PrimaryKey(i64),
^^^ the trait `Responder<'_, '_>` is not implemented for `i64`
Mail(String),
LDAPName(String),
LDAPOrMail(String)
}
#[post(/api)]
pub async fn do_something() -> Result<Json<SomeSuccessValue>, Error> {
// ---
} However, the error I'm getting is that the trait
Thankss |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It's not implemented because there's no obviously correct, semantically equivalent HTTP response to the primitives. In other words, it's not obvious what the correct HTTP response for an integer should be. Should it be the string representation of the integer? If so, what is the content-type, and in which base? Should it be a status code? Since it's not obvious, we can't implement
You cannot. How you go around this depends and what you want the responder to do when it is a impl<'r> Responder<'r, 'static> for UserId {
fn respond_to(self, req: &'r Request<'_>) -> response::Result<'static> {
let string = match self {
UserId::PrimaryKey(n) => n.to_string(),
UserId::Mail(s) | UserId::LDAPName(s) | UserId::LDAPOrMail(s) => s,
};
string.respond_to(req)
}
} |
Beta Was this translation helpful? Give feedback.
It's not implemented because there's no obviously correct, semantically equivalent HTTP response to the primitives. In other words, it's not obvious what the correct HTTP response for an integer should be. Should it be the string representation of the integer? If so, what is the content-type, and in which base? Should it be a status code? Since it's not obvious, we can't implement
Responder
.You cannot. How you go around this depends and what you want the responder to do when it is a
PrimaryKey
. If you want…