1use std::{convert::Infallible, io};
2
3use crate::{Blob, BlobRef, Kind};
4
5impl crate::WriteTo for BlobRef<'_> {
6 fn write_to(&self, out: &mut dyn io::Write) -> io::Result<()> {
8 out.write_all(self.data)
9 }
10
11 fn kind(&self) -> Kind {
12 Kind::Blob
13 }
14
15 fn size(&self) -> u64 {
16 self.data.len() as u64
17 }
18}
19
20impl crate::WriteTo for Blob {
21 fn write_to(&self, out: &mut dyn io::Write) -> io::Result<()> {
23 self.to_ref().write_to(out)
24 }
25
26 fn kind(&self) -> Kind {
27 Kind::Blob
28 }
29
30 fn size(&self) -> u64 {
31 self.to_ref().size()
32 }
33}
34
35impl Blob {
36 pub fn to_ref(&self) -> BlobRef<'_> {
38 BlobRef { data: &self.data }
39 }
40}
41
42impl BlobRef<'_> {
43 pub fn from_bytes(data: &[u8]) -> Result<BlobRef<'_>, Infallible> {
45 Ok(BlobRef { data })
46 }
47}