MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / element

Method element

atomic-core/examples/graph_codec_lab/codec.rs:213–230  ·  view source on GitHub ↗
(&mut self, value: &T)

Source from the content-addressed store, hash-verified

211}
212impl Compound<'_> {
213 fn element<T: Serialize + ?Sized>(&mut self, value: &T) -> SResult<()> {
214 if let Some((len, bytes)) = &mut self.pending {
215 let mut one = [0u8; 1];
216 if postcard::to_slice(value, &mut one).is_ok_and(|bytes| bytes.len() == 1) {
217 if bytes.len() >= *len {
218 return Err(Error("sequence exceeds declared length".into()));
219 }
220 bytes.push(one[0]);
221 return Ok(());
222 }
223 let (len, bytes) = self.pending.take().unwrap();
224 self.w.small_number(4, len as u64)?;
225 for byte in bytes {
226 ser::Serializer::serialize_u8(&mut *self.w, byte)?;
227 }
228 }
229 value.serialize(&mut *self.w)
230 }
231 fn finish(self) -> SResult<()> {
232 if let Some((len, bytes)) = self.pending {
233 if len != bytes.len() {

Callers

nothing calls this directly

Calls 6

ErrorClass · 0.85
small_numberMethod · 0.80
lenMethod · 0.45
pushMethod · 0.45
unwrapMethod · 0.45
serializeMethod · 0.45

Tested by

no test coverage detected