Trait ion_rs::value::Element [−][src]
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 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_any_int(&self) -> Option<&AnyInt>; 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>;
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.
Associated Types
type SymbolToken: SymbolToken + Debug + PartialEq
[src]
type Sequence: Sequence<Element = Self> + ?Sized + Debug + PartialEq
[src]
type Struct: Struct<FieldName = Self::SymbolToken, Element = Self> + ?Sized + Debug + PartialEq
[src]
type Builder: Builder<SymbolToken = Self::SymbolToken, Element = Self> + ?Sized
[src]
Required methods
fn ion_type(&self) -> IonType
[src]
The type of data this element represents.
fn annotations<'a>(
&'a self
) -> Box<dyn Iterator<Item = &'a Self::SymbolToken> + 'a>
[src]
&'a self
) -> Box<dyn Iterator<Item = &'a Self::SymbolToken> + 'a>
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.
fn with_annotations<I: IntoIterator<Item = Self::SymbolToken>>(
self,
annotations: I
) -> Self
[src]
self,
annotations: I
) -> Self
Return an Element
with given annotations
fn is_null(&self) -> bool
[src]
Returns whether this element is a null
value
fn as_any_int(&self) -> Option<&AnyInt>
[src]
Returns a reference to the underlying AnyInt
for this element.
This will return None
if the type is not int
or the value is any null
.
fn as_f64(&self) -> Option<f64>
[src]
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
.
fn as_decimal(&self) -> Option<&Decimal>
[src]
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
.
fn as_timestamp(&self) -> Option<&Timestamp>
[src]
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
.
fn as_str(&self) -> Option<&str>
[src]
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.
fn as_sym(&self) -> Option<&Self::SymbolToken>
[src]
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
.
fn as_bool(&self) -> Option<bool>
[src]
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
.
fn as_bytes(&self) -> Option<&[u8]>
[src]
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
.
fn as_sequence(&self) -> Option<&Self::Sequence>
[src]
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
.
fn as_struct(&self) -> Option<&Self::Struct>
[src]
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
impl Element for OwnedElement
[src]
impl Element for OwnedElement
[src]type SymbolToken = OwnedSymbolToken
type Sequence = OwnedSequence
type Struct = OwnedStruct
type Builder = OwnedElement
fn ion_type(&self) -> IonType
[src]
fn annotations<'a>(
&'a self
) -> Box<dyn Iterator<Item = &'a Self::SymbolToken> + 'a>
[src]
&'a self
) -> Box<dyn Iterator<Item = &'a Self::SymbolToken> + 'a>
fn with_annotations<I: IntoIterator<Item = Self::SymbolToken>>(
self,
annotations: I
) -> Self
[src]
self,
annotations: I
) -> Self
fn is_null(&self) -> bool
[src]
fn as_any_int(&self) -> Option<&AnyInt>
[src]
fn as_f64(&self) -> Option<f64>
[src]
fn as_decimal(&self) -> Option<&Decimal>
[src]
fn as_timestamp(&self) -> Option<&Timestamp>
[src]
fn as_str(&self) -> Option<&str>
[src]
fn as_sym(&self) -> Option<&Self::SymbolToken>
[src]
fn as_bool(&self) -> Option<bool>
[src]
fn as_bytes(&self) -> Option<&[u8]>
[src]
fn as_sequence(&self) -> Option<&Self::Sequence>
[src]
fn as_struct(&self) -> Option<&Self::Struct>
[src]
impl<'val> Element for BorrowedElement<'val>
[src]
impl<'val> Element for BorrowedElement<'val>
[src]type SymbolToken = BorrowedSymbolToken<'val>
type Sequence = BorrowedSequence<'val>
type Struct = BorrowedStruct<'val>
type Builder = BorrowedElement<'val>
fn ion_type(&self) -> IonType
[src]
fn annotations<'a>(
&'a self
) -> Box<dyn Iterator<Item = &'a Self::SymbolToken> + 'a>
[src]
&'a self
) -> Box<dyn Iterator<Item = &'a Self::SymbolToken> + 'a>
fn with_annotations<I: IntoIterator<Item = Self::SymbolToken>>(
self,
annotations: I
) -> Self
[src]
self,
annotations: I
) -> Self