MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / validate_shape

Method validate_shape

nodedb-array/src/sync/op.rs:99–117  ·  view source on GitHub ↗

Validate that `attrs` presence matches the operation kind. Returns [`ArrayError::InvalidOp`] if the shape contract is violated.

(&self)

Source from the content-addressed store, hash-verified

97 ///
98 /// Returns [`ArrayError::InvalidOp`] if the shape contract is violated.
99 pub fn validate_shape(&self) -> ArrayResult<()> {
100 match self.kind {
101 ArrayOpKind::Put => {
102 if self.attrs.is_none() {
103 return Err(ArrayError::InvalidOp {
104 detail: "Put op must carry attrs".into(),
105 });
106 }
107 }
108 ArrayOpKind::Delete | ArrayOpKind::Erase => {
109 if self.attrs.is_some() {
110 return Err(ArrayError::InvalidOp {
111 detail: format!("{:?} op must not carry attrs", self.kind),
112 });
113 }
114 }
115 }
116 Ok(())
117 }
118}
119
120#[cfg(test)]

Callers 2

apply_opMethod · 0.80
apply_opFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected