pub fn apply_data_op(&mut self, op: CrdtDataOperation<A, Entry>) -> Result<()> {
        // First check op is validly signed.
        // Note: Perms for the op are checked at the upper Sequence layer.
        let sig = op.signature.ok_or(Error::CrdtMissingOpSignature)?;
        let bytes_to_verify = utils::serialise(&op.crdt_op).map_err(|err| {
            Error::Serialisation(format!(
                "Could not serialise CRDT data operation to verify signature: {}",
                err
            ))
        })?;
        op.source.verify(&sig, &bytes_to_verify)?;

        let policy_id = op.ctx.clone();
        if self.policy_by_id(&policy_id).is_some() {
            // We have to apply the op to all branches/copies of the Sequence as it may
            // be an old operation which appends an item to the master branch of items
            for LSeqEntry {
                id,
                val: (_, item_id),
                ..
            } in self.policy.iter_entries()
            {
                // We should apply the op to this branch/copy if the Identifier of
                // this Policy is either:
                // - equal to the Policy the op depends on
                // - or greater than the Policy the data op depends on, and if this Policy
                //   depends on a greater or equal item Identifier than the Id of the data op
                let should_apply_op = match id.cmp(&policy_id) {
                    Equal => true,
                    Less => false,
                    Greater => match item_id {
                        None => true,
                        Some(item_id) => item_id >= op.crdt_op.id(),
                    },
                };

                if should_apply_op {
                    // Retrieve the LSeq corresponding this Policy
                    let lseq = self.data.get_mut(id).ok_or(Error::CrdtUnexpectedState)?;

                    // Apply the CRDT operation to the LSeq data
                    lseq.apply(op.crdt_op.clone());
                }
            }

            Ok(())
        } else {
            // Operation is not causally ready as depends on a policy
            // version we aren't aware of yet.
            // Return error so sender can retry later and/or send the missing policy op/s
            // TODO: perhaps send the last Policy Identifier as a reference to the sender
            Err(Error::OpNotCausallyReady)
        }
    }
/// Apply a remote data CRDT operation to this replica of the Sequence.
Apply a remote data CRDT operation to this replica of the Sequence.
Apply a remote data CRDT operation to this replica of the Sequence .
pub fn apply_data_op(&mut self, op: CrdtDataOperation<A, Entry>) -> Result<()> {
        // First check op is validly signed.
        // Note: Perms for the op are checked at the upper Sequence layer.
        let sig = op.signature.ok_or(Error::CrdtMissingOpSignature)?;
        let bytes_to_verify = utils::serialise(&op.crdt_op).map_err(|err| {
            Error::Serialisation(format!(
                "Could not serialise CRDT data operation to verify signature: {}",
                err
            ))
        })?;
        op.source.verify(&sig, &bytes_to_verify)?;
        let policy_id = op.ctx.clone();
        if self.policy_by_id(&policy_id).is_some() {
            // We have to apply the op to all branches/copies of the Sequence as it may
            // be an old operation which appends an item to the master branch of items
            for LSeqEntry {
                id,
                val: (_, item_id),
                ..
            } in self.policy.iter_entries()
            {
                // We should apply the op to this branch/copy if the Identifier of
                // this Policy is either:
                // - equal to the Policy the op depends on
                // - or greater than the Policy the data op depends on, and if this Policy
                //   depends on a greater or equal item Identifier than the Id of the data op
                let should_apply_op = match id.cmp(&policy_id) {
                    Equal => true,
                    Less => false,
                    Greater => match item_id {
                        None => true,
                        Some(item_id) => item_id >= op.crdt_op.id(),
                    },
                };
                if should_apply_op {
                    // Retrieve the LSeq corresponding this Policy
                    let lseq = self.data.get_mut(id).ok_or(Error::CrdtUnexpectedState)?;
                    // Apply the CRDT operation to the LSeq data
                    lseq.apply(op.crdt_op.clone());
                }
            }
            Ok(())
        } else {
            // Operation is not causally ready as depends on a policy
            // version we aren't aware of yet.
            // Return error so sender can retry later and/or send the missing policy op/s
            // TODO: perhaps send the last Policy Identifier as a reference to the sender
            Err(Error::OpNotCausallyReady)
        }
    }
pub fn apply_data_op ( & mut self , op : CrdtDataOperation < A , Entry > ) -> Result < ( ) > { // First check op is validly signed. // Note: Perms for the op are checked at the upper Sequence layer. let sig = op . signature . ok_or ( Error :: CrdtMissingOpSignature ) ? ; let bytes_to_verify = utils :: serialise ( & op . crdt_op ) . map_err ( | err | { Error :: Serialisation ( format ! ( " " err ) ) } ) ? ; op . source . verify ( & sig , & bytes_to_verify ) ? ; let policy_id = op . ctx . clone ( ) ; if self . policy_by_id ( & policy_id ) . is_some ( ) { // We have to apply the op to all branches/copies of the Sequence as it may // be an old operation which appends an item to the master branch of items for LSeqEntry { id , val : ( _ , item_id ) , .. } in self . policy . iter_entries ( ) { // We should apply the op to this branch/copy if the Identifier of // this Policy is either: // - equal to the Policy the op depends on // - or greater than the Policy the data op depends on, and if this Policy //   depends on a greater or equal item Identifier than the Id of the data op let should_apply_op = match id . cmp ( & policy_id ) { Equal => true , Less => false , Greater => match item_id { None => true , Some ( item_id ) => item_id >= op . crdt_op . id ( ) , } , } ; if should_apply_op { // Retrieve the LSeq corresponding this Policy let lseq = self . data . get_mut ( id ) . ok_or ( Error :: CrdtUnexpectedState ) ? ; // Apply the CRDT operation to the LSeq data lseq . apply ( op . crdt_op . clone ( ) ) ; } } Ok ( ( ) ) } else { // Operation is not causally ready as depends on a policy // version we aren't aware of yet. // Return error so sender can retry later and/or send the missing policy op/s // TODO: perhaps send the last Policy Identifier as a reference to the sender Err ( Error :: OpNotCausallyReady ) } }
Apply a remote data CRDT operation to this replica of the Sequence.
Apply a remote data CRDT operation to this replica of the Sequence .
&mut self
op
CrdtDataOperation<A, Entry>
&mut self
op
CrdtDataOperation<A, Entry>