pub trait Element where
    Self: From<i64> + From<bool> + From<Decimal> + From<Timestamp> + From<f64> + From<BigInt> + Debug + PartialEq
{ type SymbolToken: SymbolToken + Debug + PartialEq; type Sequence: Sequence<Element = Self> + ?Sized + Debug + PartialEq; type Struct: Struct<FieldName = Self::SymbolToken, Element = Self> + ?Sized + Debug + PartialEq; type Builder: Builder<SymbolToken = Self::SymbolToken, Element = Self> + ?Sized;
Show 14 methods fn ion_type(&self) -> IonType; fn annotations<'a>(
        &'a self
    ) -> Box<dyn Iterator<Item = &'a Self::SymbolToken> + 'a>; fn with_annotations<I: IntoIterator<Item = Self::SymbolToken>>(
        self,
        annotations: I
    ) -> Self; fn is_null(&self) -> bool; fn as_integer(&self) -> Option<&Integer>; fn as_f64(&self) -> Option<f64>; fn as_decimal(&self) -> Option<&Decimal>; fn as_timestamp(&self) -> Option<&Timestamp>; fn as_str(&self) -> Option<&str>; fn as_sym(&self) -> Option<&Self::SymbolToken>; fn as_bool(&self) -> Option<bool>; fn as_bytes(&self) -> Option<&[u8]>; fn as_sequence(&self) -> Option<&Self::Sequence>; fn as_struct(&self) -> Option<&Self::Struct>;
}
Expand description

Represents a either a borrowed or owned Ion datum. There are/will be specific APIs for borrowed and owned implementations, but this trait unifies operations on either.

Required Associated Types

Required Methods

The type of data this element represents.

The annotations for this element.

Usage
// simple function to extract the annotations to owned strings.
// will panic if the text is not there!
fn annotation_strings<T: Element>(elem: &T) -> Vec<String> {
    elem.annotations().map(|tok| tok.text().unwrap().into()).collect()
}

let strs = vec!["a", "b", "c"];
let owned_elem = OwnedElement::new(
    strs.iter().map(|s| (*s).into()).collect(),
    OwnedValue::String("moo".into())
);
let borrowed_elem = BorrowedElement::new(
    strs.iter().map(|s| (*s).into()).collect(),
    BorrowedValue::String("moo")
);

let expected: Vec<String> = strs.iter().map(|s| (*s).into()).collect();
assert_eq!(expected, annotation_strings(&owned_elem));
assert_eq!(expected, annotation_strings(&borrowed_elem));

Note that this uses a Box<dyn Iterator<...>> to capture the borrow cleanly without without generic associated types (GAT). In theory, when GAT lands, this could be replaced with static polymorphism.

Return an Element with given annotations

Returns whether this element is a null value

Returns a reference to the underlying Integer for this element.

This will return None if the type is not int or the value is any null.

Returns a reference to the underlying float value for this element.

This will return None if the type is not float or the value is any null.

Returns a reference to the underlying Decimal for this element.

This will return None if the type is not decimal or the value is any null.

Returns a reference to the underlying Timestamp for this element.

This will return None if the type is not timestamp or the value is any null.

Returns a slice to the textual value of this element.

This will return None in the case that the type is not string/symbol, if the value is any null, or the text of the symbol is not defined.

Returns a reference to the SymbolToken of this element.

This will return None in the case that the type is not symbol or the value is any null.

Returns a reference to the boolean value of this element.

This will return None in the case that the type is not bool or the value is any null.

Returns a reference to the underlying bytes of this element.

This will return None in the case that the type is not blob/clob or the value is any null.

Returns a reference to the Sequence of this element.

This will return None in the case that the type is not sexp/list or if the value is any null.

Returns a reference to the Struct of this element.

This will return None in the case that the type is not struct or the value is any null.

Implementors