Struct ion_rs::element::Annotations
source · 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§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for Annotations
impl Debug for Annotations
source§impl<S: Into<Symbol>> FromIterator<S> for Annotations
impl<S: Into<Symbol>> FromIterator<S> for Annotations
source§fn from_iter<T: IntoIterator<Item = S>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = S>>(iter: T) -> Self
source§impl<'a> IntoIterator for &'a Annotations
impl<'a> IntoIterator for &'a Annotations
source§impl IntoIterator for Annotations
impl IntoIterator for Annotations
source§impl PartialEq<Annotations> for Annotations
impl PartialEq<Annotations> for Annotations
source§fn eq(&self, other: &Annotations) -> bool
fn eq(&self, other: &Annotations) -> bool
self
and other
values to be equal, and is used
by ==
.