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/clientinit.rs | |
| parent | use ProtocolError for From derive (diff) | |
handshare and signalproxy/rpccall error handling
Diffstat (limited to 'src/message/handshake/clientinit.rs')
| -rw-r--r-- | src/message/handshake/clientinit.rs | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/src/message/handshake/clientinit.rs b/src/message/handshake/clientinit.rs index 9d35243..3011821 100644 --- a/src/message/handshake/clientinit.rs +++ b/src/message/handshake/clientinit.rs @@ -63,13 +63,27 @@ impl HandshakeSerialize for ClientInit { } } -impl From<VariantMap> for ClientInit { - fn from(mut input: VariantMap) -> Self { - ClientInit { - client_version: input.remove("ClientVersion").unwrap().try_into().unwrap(), - client_date: input.remove("ClientDate").unwrap().try_into().unwrap(), - client_features: input.remove("Features").unwrap().try_into().unwrap(), - feature_list: input.remove("FeatureList").unwrap().try_into().unwrap(), - } +impl TryFrom<VariantMap> for ClientInit { + type Error = ProtocolError; + + fn try_from(mut input: VariantMap) -> Result<Self, Self::Error> { + Ok(ClientInit { + client_version: input + .remove("ClientVersion") + .ok_or_else(|| ProtocolError::MissingField("ClientVersion".to_string()))? + .try_into()?, + client_date: input + .remove("ClientDate") + .ok_or_else(|| ProtocolError::MissingField("ClientDate".to_string()))? + .try_into()?, + client_features: input + .remove("Features") + .ok_or_else(|| ProtocolError::MissingField("Features".to_string()))? + .try_into()?, + feature_list: input + .remove("FeatureList") + .ok_or_else(|| ProtocolError::MissingField("FeatureList".to_string()))? + .try_into()?, + }) } } |
