libvctrl_core 3.2.0

Reference implementations of the libvctrl contracts (in-memory store, SHA-512 hasher, binary codec)
Documentation
use libvctrl_handler::{Blob, VctrlError};

#[derive(Debug, Default)]
pub struct BlobBuilder {
    data: Vec<u8>,
}

impl BlobBuilder {
    #[must_use]
    pub const fn new() -> Self {
        Self { data: Vec::new() }
    }

    #[must_use]
    pub fn with_data(mut self, data: Vec<u8>) -> Self {
        self.data = data;
        self
    }

    pub fn build(self) -> Result<Blob, VctrlError> {
        Blob::new(self.data)
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn builder_empty_data_builds_ok() -> Result<(), VctrlError> {
        let blob = BlobBuilder::new().build()?;
        assert!(blob.data().is_empty());
        Ok(())
    }

    #[test]
    fn builder_with_data_builds_ok() -> Result<(), VctrlError> {
        let data = vec![1_u8, 2, 3];
        let blob = BlobBuilder::new().with_data(data.clone()).build()?;
        assert_eq!(blob.data(), data.as_slice());
        Ok(())
    }
}