fusionsql_core/field/
field_mask.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Default, Serialize, Deserialize)]
4#[serde(transparent)]
5#[cfg_attr(feature = "with-openapi", derive(utoipa::ToSchema))]
6pub struct FieldMask {
7 pub paths: Vec<String>,
8}
9
10impl FieldMask {
11 pub fn new<I, S>(paths: I) -> Self
12 where
13 I: IntoIterator<Item = S>,
14 S: Into<String>,
15 {
16 Self { paths: paths.into_iter().map(|s| s.into()).collect() }
17 }
18
19 pub fn is_empty(&self) -> bool {
20 self.paths.is_empty()
21 }
22
23 #[inline]
24 pub fn non_empty(&self) -> bool {
25 !self.is_empty()
26 }
27
28 pub fn hit(&self, path: &str) -> bool {
30 self.is_empty() || self.paths.iter().any(|p| p == path)
31 }
32}