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:
parent
ab6c56b7de
commit
bfe4e9fa27
9
ruma-serde/src/can_be_empty.rs
Normal file
9
ruma-serde/src/can_be_empty.rs
Normal 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()
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
|
||||
use serde::de::{Deserialize, IntoDeserializer};
|
||||
|
||||
pub mod can_be_empty;
|
||||
pub mod duration;
|
||||
pub mod empty;
|
||||
pub mod json_string;
|
||||
@ -9,6 +10,7 @@ pub mod test;
|
||||
pub mod time;
|
||||
pub mod urlencoded;
|
||||
|
||||
pub use can_be_empty::{is_empty, CanBeEmpty};
|
||||
pub use empty::vec_as_map_of_empty;
|
||||
|
||||
/// Check whether a value is equal to its default value.
|
||||
|
Loading…
x
Reference in New Issue
Block a user