client-api: Panic if capability serialization fails
There could only be a serialization failure if there is a bug in serde or serde_json.
This commit is contained in:
parent
408545d287
commit
cd0fc1865c
@ -86,12 +86,16 @@ impl Capabilities {
|
|||||||
///
|
///
|
||||||
/// Prefer to use the public fields of `Capabilities` where possible; this method is meant to be
|
/// Prefer to use the public fields of `Capabilities` where possible; this method is meant to be
|
||||||
/// used for unsupported capabilities only.
|
/// used for unsupported capabilities only.
|
||||||
pub fn get(&self, capability: &str) -> serde_json::Result<Option<Cow<'_, JsonValue>>> {
|
pub fn get(&self, capability: &str) -> Option<Cow<'_, JsonValue>> {
|
||||||
Ok(match capability {
|
fn serialize<T: Serialize>(cap: &T) -> JsonValue {
|
||||||
"m.change_password" => Some(Cow::Owned(to_json_value(&self.change_password)?)),
|
to_json_value(cap).expect("capability serialization to succeed")
|
||||||
"m.room_versions" => Some(Cow::Owned(to_json_value(&self.room_versions)?)),
|
}
|
||||||
|
|
||||||
|
match capability {
|
||||||
|
"m.change_password" => Some(Cow::Owned(serialize(&self.change_password))),
|
||||||
|
"m.room_versions" => Some(Cow::Owned(serialize(&self.room_versions))),
|
||||||
_ => self.custom_capabilities.get(capability).map(Cow::Borrowed),
|
_ => self.custom_capabilities.get(capability).map(Cow::Borrowed),
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets a capability to the given value.
|
/// Sets a capability to the given value.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user