Remove Option wrapper around directory filters

This commit is contained in:
Timo Kösters 2020-10-17 23:06:52 +02:00 committed by GitHub
parent a67a396ee0
commit 90bd4874e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 4 deletions

View File

@ -35,8 +35,8 @@ ruma_api! {
pub since: Option<&'a str>, pub since: Option<&'a str>,
/// Filter to apply to the results. /// Filter to apply to the results.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Filter::is_empty")]
pub filter: Option<Filter<'a>>, pub filter: Filter<'a>,
/// Network to fetch the public room lists from. /// Network to fetch the public room lists from.
#[serde(flatten, skip_serializing_if = "ruma_serde::is_default")] #[serde(flatten, skip_serializing_if = "ruma_serde::is_default")]

View File

@ -98,6 +98,7 @@ impl From<PublicRoomsChunkInit> for PublicRoomsChunk {
/// A filter for public rooms lists /// A filter for public rooms lists
#[derive(Clone, Debug, Default, Outgoing, Serialize)] #[derive(Clone, Debug, Default, Outgoing, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[incoming_derive(Default)]
pub struct Filter<'a> { pub struct Filter<'a> {
/// A string to search for in the room metadata, e.g. name, topic, canonical alias etc. /// A string to search for in the room metadata, e.g. name, topic, canonical alias etc.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
@ -109,6 +110,11 @@ impl Filter<'_> {
pub fn new() -> Self { pub fn new() -> Self {
Default::default() Default::default()
} }
/// Returns `true` if the filter is empty.
pub fn is_empty(&self) -> bool {
self.generic_search_term.is_none()
}
} }
/// Information about which networks/protocols from application services on the /// Information about which networks/protocols from application services on the

View File

@ -27,8 +27,8 @@ ruma_api! {
pub since: Option<&'a str>, pub since: Option<&'a str>,
/// Filter to apply to the results. /// Filter to apply to the results.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Filter::is_empty")]
pub filter: Option<Filter<'a>>, pub filter: Filter<'a>,
/// Network to fetch the public room lists from. /// Network to fetch the public room lists from.
#[serde(flatten, skip_serializing_if = "ruma_serde::is_default")] #[serde(flatten, skip_serializing_if = "ruma_serde::is_default")]