// Adds 3 annotations, then in a second call to update_annotations():
// - removes one
// - modifies one
// - adds a new one
Adds 3 annotations, then in a second call to update_annotations():
removes one
modifies one
adds a new one
Adds 3 annotations then in a second call to update_annotations () : removes one modifies one adds a new one
fn update_some_annotations() -> Result<(), anyhow::Error> {
        const NAMESPACE: &str = "HARDCODED_NAMESPACE";
        const ID1: &str = "id1";
        const ID2: &str = "id2";
        const ID3: &str = "id3";
        const ID4: &str = "id4";
        let mut holder = AnnotationHolder::new();
        // Add initial annotations.
        holder.update_annotations(
            vec![
                felement::Annotation {
                    key: make_annotation_key(NAMESPACE, ID1),
                    value: make_annotation_text("initial value 1"),
                },
                felement::Annotation {
                    key: make_annotation_key(NAMESPACE, ID2),
                    value: make_annotation_text("initial value 2"),
                },
                felement::Annotation {
                    key: make_annotation_key(NAMESPACE, ID3),
                    value: make_annotation_text("initial value 3"),
                },
            ],
            vec![],
        )?;
        // Delete one annotation, modify another, add a third.
        holder.update_annotations(
            vec![
                felement::Annotation {
                    key: make_annotation_key(NAMESPACE, ID3),
                    value: make_annotation_text("updated value 3"),
                },
                felement::Annotation {
                    key: make_annotation_key(NAMESPACE, ID4),
                    value: make_annotation_text("new value 4"),
                },
            ],
            vec![make_annotation_key(NAMESPACE, ID2)],
        )?;
        let mut annotations = holder.get_annotations()?;
        annotations.sort_by(|a, b| compare_annotation_keys(&a.key, &b.key));
        assert_eq!(annotations.len(), 3);
        assert_text_annotation_matches(&annotations[0], NAMESPACE, ID1, "initial value 1");
        assert_text_annotation_matches(&annotations[1], NAMESPACE, ID3, "updated value 3");
        assert_text_annotation_matches(&annotations[2], NAMESPACE, ID4, "new value 4");
        Ok(())
    }
fn update_some_annotations ( ) -> Result < ( ) , anyhow :: Error > { const NAMESPACE : & str = " " ; const ID1 : & str = " " ; const ID2 : & str = " " ; const ID3 : & str = " " ; const ID4 : & str = " " ; let mut holder = AnnotationHolder :: new ( ) ; // Add initial annotations. holder . update_annotations ( vec ! [ felement Annotation { key make_annotation_key ( NAMESPACE ID1 ) value make_annotation_text ( " " ) } felement Annotation { key make_annotation_key ( NAMESPACE ID2 ) value make_annotation_text ( " " ) } felement Annotation { key make_annotation_key ( NAMESPACE ID3 ) value make_annotation_text ( " " ) } ] , vec ! [ ] , ) ? ; // Delete one annotation, modify another, add a third. holder . update_annotations ( vec ! [ felement Annotation { key make_annotation_key ( NAMESPACE ID3 ) value make_annotation_text ( " " ) } felement Annotation { key make_annotation_key ( NAMESPACE ID4 ) value make_annotation_text ( " " ) } ] , vec ! [ make_annotation_key ( NAMESPACE ID2 ) ] , ) ? ; let mut annotations = holder . get_annotations ( ) ? ; annotations . sort_by ( | a , b | compare_annotation_keys ( & a . key , & b . key ) ) ; assert_eq ! ( annotations len ( ) 3 ) ; assert_text_annotation_matches ( & annotations [ 0 ] , NAMESPACE , ID1 , " " ) ; assert_text_annotation_matches ( & annotations [ 1 ] , NAMESPACE , ID3 , " " ) ; assert_text_annotation_matches ( & annotations [ 2 ] , NAMESPACE , ID4 , " " ) ; Ok ( ( ) ) }
Adds 3 annotations, then in a second call to update_annotations():
 removes one
 modifies one
 adds a new one
Adds 3 annotations then in a second call to update_annotations () : removes one modifies one adds a new one