pub fn update_annotations(
        &mut self,
        mut annotations_to_set: Vec<felement::Annotation>,
        annotations_to_delete: Vec<felement::AnnotationKey>,
    ) -> Result<(), AnnotationError> {
        // Gather the keys that will be updated.
        let mut keys_to_set = HashSet::new();
        for annotation in annotations_to_set.iter() {
            if annotation.key.namespace.len() == 0 {
                // Empty namespace is illegal.
                return Err(AnnotationError::Update(felement::UpdateAnnotationsError::InvalidArgs));
            }
            keys_to_set.insert(Key::from_fidl_key(&annotation.key));
        }

        // Gather keys that will be deleted.
        let mut keys_to_delete = HashSet::new();
        for key in annotations_to_delete.iter() {
            if key.namespace.len() == 0 {
                // Empty namespace is illegal.
                return Err(AnnotationError::Update(felement::UpdateAnnotationsError::InvalidArgs));
            }
            keys_to_delete.insert(Key::from_fidl_key(&key));
        }

        // Detect illegality: setting multiple annotations with the same key.
        if keys_to_set.len() != annotations_to_set.len() {
            return Err(AnnotationError::Update(felement::UpdateAnnotationsError::InvalidArgs));
        }

        // Detect illegality: both setting and deleting annotations with the same key.
        if !keys_to_set.is_disjoint(&keys_to_delete) {
            return Err(AnnotationError::Update(felement::UpdateAnnotationsError::InvalidArgs));
        }

        // Detect illegality: maximum number of annotations would be exceeded.
        // To compute the number of annotations that will exists after applying this operation:
        //   - start with the existing number of annotations
        //   - add one for every annotation-to-set whose key doesn't already exist
        //   - subtract one for every annotation-to-delete whose key does already exist
        let mut count = self.annotations.len();
        for k in keys_to_set {
            if !self.annotations.contains_key(&k) {
                count += 1
            }
        }
        for k in keys_to_delete {
            if self.annotations.contains_key(&k) {
                count -= 1
            }
        }
        if count > MAX_ANNOTATIONS {
            return Err(AnnotationError::Update(
                felement::UpdateAnnotationsError::TooManyAnnotations,
            ));
        }

        // Everything looks legal, so we can go ahead and mutate our map.
        for annotation in annotations_to_set.drain(..) {
            let key = Key::from_fidl_key(&annotation.key);
            self.annotations.insert(key, annotation.value);
        }
        for key in annotations_to_delete.iter() {
            let key = Key::from_fidl_key(key);
            self.annotations.remove(&key);
        }

        self.notify_watch_subscribers();

        Ok(())
    }
// Update (add/modify/delete) annotations as specified by fuchsia.element.AnnotationController.UpdateAnnotations()
Update (add/modify/delete) annotations as specified by fuchsia.element.AnnotationController.UpdateAnnotations()
Update ( add / modify / delete ) annotations as specified by fuchsia . element . AnnotationController . UpdateAnnotations ()
pub fn update_annotations(
        &mut self,
        mut annotations_to_set: Vec<felement::Annotation>,
        annotations_to_delete: Vec<felement::AnnotationKey>,
    ) -> Result<(), AnnotationError> {
        // Gather the keys that will be updated.
        let mut keys_to_set = HashSet::new();
        for annotation in annotations_to_set.iter() {
            if annotation.key.namespace.len() == 0 {
                // Empty namespace is illegal.
                return Err(AnnotationError::Update(felement::UpdateAnnotationsError::InvalidArgs));
            }
            keys_to_set.insert(Key::from_fidl_key(&annotation.key));
        }
        // Gather keys that will be deleted.
        let mut keys_to_delete = HashSet::new();
        for key in annotations_to_delete.iter() {
            if key.namespace.len() == 0 {
                // Empty namespace is illegal.
                return Err(AnnotationError::Update(felement::UpdateAnnotationsError::InvalidArgs));
            }
            keys_to_delete.insert(Key::from_fidl_key(&key));
        }
        // Detect illegality: setting multiple annotations with the same key.
        if keys_to_set.len() != annotations_to_set.len() {
            return Err(AnnotationError::Update(felement::UpdateAnnotationsError::InvalidArgs));
        }
        // Detect illegality: both setting and deleting annotations with the same key.
        if !keys_to_set.is_disjoint(&keys_to_delete) {
            return Err(AnnotationError::Update(felement::UpdateAnnotationsError::InvalidArgs));
        }
        // Detect illegality: maximum number of annotations would be exceeded.
        // To compute the number of annotations that will exists after applying this operation:
        //   - start with the existing number of annotations
        //   - add one for every annotation-to-set whose key doesn't already exist
        //   - subtract one for every annotation-to-delete whose key does already exist
        let mut count = self.annotations.len();
        for k in keys_to_set {
            if !self.annotations.contains_key(&k) {
                count += 1
            }
        }
        for k in keys_to_delete {
            if self.annotations.contains_key(&k) {
                count -= 1
            }
        }
        if count > MAX_ANNOTATIONS {
            return Err(AnnotationError::Update(
                felement::UpdateAnnotationsError::TooManyAnnotations,
            ));
        }
        // Everything looks legal, so we can go ahead and mutate our map.
        for annotation in annotations_to_set.drain(..) {
            let key = Key::from_fidl_key(&annotation.key);
            self.annotations.insert(key, annotation.value);
        }
        for key in annotations_to_delete.iter() {
            let key = Key::from_fidl_key(key);
            self.annotations.remove(&key);
        }
        self.notify_watch_subscribers();
        Ok(())
    }
pub fn update_annotations ( & mut self , mut annotations_to_set : Vec < felement :: Annotation > , annotations_to_delete : Vec < felement :: AnnotationKey > , ) -> Result < ( ) , AnnotationError > { // Gather the keys that will be updated. let mut keys_to_set = HashSet :: new ( ) ; for annotation in annotations_to_set . iter ( ) { if annotation . key . namespace . len ( ) == 0 { // Empty namespace is illegal. return Err ( AnnotationError :: Update ( felement :: UpdateAnnotationsError :: InvalidArgs ) ) ; } keys_to_set . insert ( Key :: from_fidl_key ( & annotation . key ) ) ; } // Gather keys that will be deleted. let mut keys_to_delete = HashSet :: new ( ) ; for key in annotations_to_delete . iter ( ) { if key . namespace . len ( ) == 0 { // Empty namespace is illegal. return Err ( AnnotationError :: Update ( felement :: UpdateAnnotationsError :: InvalidArgs ) ) ; } keys_to_delete . insert ( Key :: from_fidl_key ( & key ) ) ; } // Detect illegality: setting multiple annotations with the same key. if keys_to_set . len ( ) != annotations_to_set . len ( ) { return Err ( AnnotationError :: Update ( felement :: UpdateAnnotationsError :: InvalidArgs ) ) ; } // Detect illegality: both setting and deleting annotations with the same key. if ! keys_to_set . is_disjoint ( & keys_to_delete ) { return Err ( AnnotationError :: Update ( felement :: UpdateAnnotationsError :: InvalidArgs ) ) ; } // Detect illegality: maximum number of annotations would be exceeded. // To compute the number of annotations that will exists after applying this operation: //   - start with the existing number of annotations //   - add one for every annotation-to-set whose key doesn't already exist //   - subtract one for every annotation-to-delete whose key does already exist let mut count = self . annotations . len ( ) ; for k in keys_to_set { if ! self . annotations . contains_key ( & k ) { count += 1 } } for k in keys_to_delete { if self . annotations . contains_key ( & k ) { count -= 1 } } if count > MAX_ANNOTATIONS { return Err ( AnnotationError :: Update ( felement :: UpdateAnnotationsError :: TooManyAnnotations , ) ) ; } // Everything looks legal, so we can go ahead and mutate our map. for annotation in annotations_to_set . drain ( .. ) { let key = Key :: from_fidl_key ( & annotation . key ) ; self . annotations . insert ( key , annotation . value ) ; } for key in annotations_to_delete . iter ( ) { let key = Key :: from_fidl_key ( key ) ; self . annotations . remove ( & key ) ; } self . notify_watch_subscribers ( ) ; Ok ( ( ) ) }
Update (add/modify/delete) annotations as specified by fuchsia.element.AnnotationController.UpdateAnnotations()
Update ( add / modify / delete ) annotations as specified by fuchsia . element . AnnotationController . UpdateAnnotations ()
&mut self
annotations_to_set
Vec<felement::Annotation>
annotations_to_delete
Vec<felement::AnnotationKey>
&mut self
annotations_to_set
Vec<felement::Annotation>
annotations_to_delete
Vec<felement::AnnotationKey>