diff options
| author | Max Audron <me@audron.dev> | 2026-02-21 17:25:52 +0100 |
|---|---|---|
| committer | Max Audron <me@audron.dev> | 2026-02-21 17:25:52 +0100 |
| commit | e63ecc10aa426e3aba416fd05a3f568d719a79a3 (patch) | |
| tree | e1a8dc6e4197e51ddeb3d631410acec9eda3cf6a /src/message/handshake/clientlogin.rs | |
| parent | use ProtocolError for From derive (diff) | |
handshare and signalproxy/rpccall error handling
Diffstat (limited to 'src/message/handshake/clientlogin.rs')
| -rw-r--r-- | src/message/handshake/clientlogin.rs | 20 |
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()?, + }) } } |
