| 15 | use crate::schema::attr_spec::AttrSpec; |
| 16 | |
| 17 | pub fn check(array: &str, attrs: &[AttrSpec]) -> ArrayResult<()> { |
| 18 | if attrs.is_empty() { |
| 19 | return Err(ArrayError::InvalidSchema { |
| 20 | array: array.to_string(), |
| 21 | detail: "at least one attribute is required".to_string(), |
| 22 | }); |
| 23 | } |
| 24 | let mut seen = HashSet::with_capacity(attrs.len()); |
| 25 | for a in attrs { |
| 26 | if !seen.insert(a.name.as_str()) { |
| 27 | return Err(ArrayError::InvalidAttr { |
| 28 | array: array.to_string(), |
| 29 | attr: a.name.clone(), |
| 30 | detail: "duplicate attribute name".to_string(), |
| 31 | }); |
| 32 | } |
| 33 | } |
| 34 | Ok(()) |
| 35 | } |
| 36 | |
| 37 | #[cfg(test)] |
| 38 | mod tests { |