pub struct Annotations { /* private fields */ }
Expand description
An ordered sequence of symbols that convey additional, application-specific information about their associated Ion value.
The IntoAnnotations
trait is a convenient way to convert collections of symbol convertible
things (including &str
and String
) into this sequence.
use ion_rs::element::{Annotations, IntoAnnotations};
let annotations: Annotations = ["foo", "bar", "baz"].into_annotations();
for annotation in &annotations {
assert_eq!(annotation.text().map(|s| s.len()), Some(3));
}
Implementations§
Source§impl Annotations
impl Annotations
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of annotations in this sequence.
use ion_rs::element::{Annotations, IntoAnnotations};
let annotations: Annotations = ["foo", "bar", "baz"].into_annotations();
assert_eq!(annotations.len(), 3);
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if this sequence contains zero annotations. Otherwise, returns false
.
use ion_rs::element::{Annotations, IntoAnnotations};
let annotations: Annotations = ["foo", "bar", "baz"].into_annotations();
assert!(!annotations.is_empty());
Sourcepub fn contains<S: AsRef<str>>(&self, query: S) -> bool
pub fn contains<S: AsRef<str>>(&self, query: S) -> bool
Returns true
if any symbol in this annotations sequence is equal to the provided text.
Otherwise, returns false
.
use ion_rs::element::{Annotations, IntoAnnotations};
let annotations: Annotations = ["foo", "bar", "baz"].into_annotations();
assert!(annotations.contains("foo"));
assert!(annotations.contains("bar"));
assert!(annotations.contains("baz"));
assert!(!annotations.contains("quux"));
assert!(!annotations.contains("quuz"));
Sourcepub fn first(&self) -> Option<&str>
pub fn first(&self) -> Option<&str>
Returns the text of the first annotation in this sequence.
If the sequence is empty, returns None
.
If the first annotation in the sequence is $0
(symbol ID 0), returns None
.
Otherwise, returns a Some(&str)
containing the text.
To view the first annotation as a Symbol rather than a &str
, use
annotations.iter().next()
.
use ion_rs::element::{Annotations, IntoAnnotations};
use ion_rs::Symbol;
let annotations: Annotations = ["foo", "bar", "baz"].into_annotations();
assert_eq!(annotations.first(), Some("foo"));
let empty_sequence: Vec<&str> = vec![];
let annotations: Annotations = empty_sequence.into_annotations();
assert_eq!(annotations.first(), None);
let annotations: Annotations = [Symbol::unknown_text()].into_annotations();
assert_eq!(annotations.first(), None)
Trait Implementations§
Source§impl Clone for Annotations
impl Clone for Annotations
Source§fn clone(&self) -> Annotations
fn clone(&self) -> Annotations
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read more