semiont 0.7.2

Semiont's Rust SDK: the protocol's types, the transport contract and a client of the bus over it, and what a client needs to name its principals and hold its roles, as protocol/specs/ states it.
Documentation
//! Bind: linking a reference to what it refers to.

use crate::channels::{BindBodyError, BindInitiate, BindUpdateBody};
use crate::client::Links;
use crate::errors::SemiontError;
use crate::transport::Envelope;
use crate::types::{AnnotationId, ResourceId};
use crate::types::{
    BindBodyOperation, BindInitiateCommand, BindUpdateBodyCommand, ResourceErrorEvent,
};

pub struct BindNamespace {
    links: Links,
}

impl BindNamespace {
    pub(crate) fn new(links: Links) -> BindNamespace {
        BindNamespace { links }
    }

    /// Change an annotation's body. Confirmed: it resolves when the change is
    /// recorded, and fails with the failure the knowledge base answered.
    pub async fn body(
        &self,
        resource_id: &ResourceId,
        annotation_id: &AnnotationId,
        operations: Vec<BindBodyOperation>,
    ) -> Result<(), SemiontError> {
        self.links
            .request::<BindUpdateBody>(&BindUpdateBodyCommand {
                _user_id: None,
                annotation_id: annotation_id.clone(),
                resource_id: resource_id.clone(),
                operations,
            })
            .await?;
        Ok(())
    }

    /// Signal: a binding is wanted for an annotation.
    pub fn initiate(&self, input: BindInitiateCommand) {
        self.links
            .signal::<BindInitiate>(&input, Envelope::default());
    }

    /// Signal: a body update failed where nothing could show it.
    pub fn report_body_error(&self, input: ResourceErrorEvent) {
        self.links
            .signal::<BindBodyError>(&input, Envelope::default());
    }
}