aboutsummaryrefslogtreecommitdiff
path: root/src/message/handshake/clientlogin.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/message/handshake/clientlogin.rs')
-rw-r--r--src/message/handshake/clientlogin.rs20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/message/handshake/clientlogin.rs b/src/message/handshake/clientlogin.rs
index 4be4442..b1d9672 100644
--- a/src/message/handshake/clientlogin.rs
+++ b/src/message/handshake/clientlogin.rs
@@ -20,11 +20,19 @@ impl HandshakeSerialize for ClientLogin {
}
}
-impl From<VariantMap> for ClientLogin {
- fn from(mut input: VariantMap) -> Self {
- ClientLogin {
- user: input.remove("User").unwrap().try_into().unwrap(),
- password: input.remove("Password").unwrap().try_into().unwrap(),
- }
+impl TryFrom<VariantMap> for ClientLogin {
+ type Error = ProtocolError;
+
+ fn try_from(mut input: VariantMap) -> Result<Self, Self::Error> {
+ Ok(ClientLogin {
+ user: input
+ .remove("User")
+ .ok_or_else(|| ProtocolError::MissingField("User".to_string()))?
+ .try_into()?,
+ password: input
+ .remove("Password")
+ .ok_or_else(|| ProtocolError::MissingField("Password".to_string()))?
+ .try_into()?,
+ })
}
}