Add ruma_serde::is_empty

This will be used for serde attributes that are copied to incoming types
and thus actually have to function for multiple types.
This commit is contained in:
Jonas Platte 2020-08-28 22:50:30 +02:00
parent ab6c56b7de
commit bfe4e9fa27
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
2 changed files with 11 additions and 0 deletions

View File

@ -0,0 +1,9 @@
pub trait CanBeEmpty {
/// Check whether `self` is empty.
fn is_empty(&self) -> bool;
}
/// Check whether a value is empty.
pub fn is_empty<T: CanBeEmpty>(val: &T) -> bool {
val.is_empty()
}

View File

@ -2,6 +2,7 @@
use serde::de::{Deserialize, IntoDeserializer}; use serde::de::{Deserialize, IntoDeserializer};
pub mod can_be_empty;
pub mod duration; pub mod duration;
pub mod empty; pub mod empty;
pub mod json_string; pub mod json_string;
@ -9,6 +10,7 @@ pub mod test;
pub mod time; pub mod time;
pub mod urlencoded; pub mod urlencoded;
pub use can_be_empty::{is_empty, CanBeEmpty};
pub use empty::vec_as_map_of_empty; pub use empty::vec_as_map_of_empty;
/// Check whether a value is equal to its default value. /// Check whether a value is equal to its default value.