client-api: Improve docs for Capabilities

This commit is contained in:
Jonas Platte 2021-02-15 15:37:43 +01:00
parent 5aba8935ad
commit 408545d287
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67

View File

@ -82,7 +82,10 @@ impl Capabilities {
Default::default()
}
/// Returns value of the given capability.
/// Returns the value of the given capability.
///
/// Prefer to use the public fields of `Capabilities` where possible; this method is meant to be
/// used for unsupported capabilities only.
pub fn get(&self, capability: &str) -> serde_json::Result<Option<Cow<'_, JsonValue>>> {
Ok(match capability {
"m.change_password" => Some(Cow::Owned(to_json_value(&self.change_password)?)),
@ -92,6 +95,10 @@ impl Capabilities {
}
/// Sets a capability to the given value.
///
/// Prefer to use the public fields of `Capabilities` where possible; this method is meant to be
/// used for unsupported capabilities only and does not allow setting arbitrary data for
/// supported ones.
pub fn set(&mut self, capability: &str, value: JsonValue) -> serde_json::Result<()> {
match capability {
"m.change_password" => self.change_password = from_json_value(value)?,