pub struct Element { /* private fields */ }Expand description
An (annotations, value) pair representing an Ion value.
Implementations§
Source§impl Element
impl Element
Sourcepub fn location(&self) -> &SourceLocation
pub fn location(&self) -> &SourceLocation
Returns the source location (row, column) of this element in the original Ion text.
The location metadata is primarily intended for error reporting and debugging purposes, helping applications provide meaningful feedback to users about the source of issues.
§Returns
Some((row, column))- Position where this element was found in the source textNone- Location information is not available
§Important
Location information is best-effort and may not be available in all cases:
- Elements created programmatically won’t have locations
- Some parsing scenarios might not preserve location data
- Binary Ion data does not contain location information
Do not rely on this metadata for programmatic manipulation of Ion data.
Sourcepub fn into_value(self) -> Value
pub fn into_value(self) -> Value
Sourcepub fn into_annotations(self) -> Annotations
pub fn into_annotations(self) -> Annotations
Consumes self and returns this Element’s Annotations.
Sourcepub fn into_parts(self) -> (Annotations, Value)
pub fn into_parts(self) -> (Annotations, Value)
Consumes self and returns this Element’s Annotations and Value.
pub fn null(null_type: IonType) -> Element
pub fn boolean(value: bool) -> Element
pub fn string<I: Into<Str>>(str: I) -> Element
pub fn symbol<I: Into<Symbol>>(symbol: I) -> Element
pub fn int<I: Into<Int>>(integer: I) -> Element
pub fn decimal(decimal: Decimal) -> Element
pub fn timestamp(timestamp: Timestamp) -> Element
pub fn float(float: f64) -> Element
pub fn clob<A: AsRef<[u8]>>(bytes: A) -> Element
pub fn blob<A: AsRef<[u8]>>(bytes: A) -> Element
pub fn sequence_builder() -> SequenceBuilder
pub fn struct_builder() -> StructBuilder
pub fn ion_type(&self) -> IonType
pub fn annotations(&self) -> &Annotations
pub fn with_annotations<I: IntoAnnotations>(self, annotations: I) -> Self
pub fn is_null(&self) -> bool
pub fn as_int(&self) -> Option<&Int>
pub fn expect_int(&self) -> IonResult<&Int>
pub fn try_into_int(self) -> ConversionOperationResult<Element, Int>
pub fn as_i64(&self) -> Option<i64>
pub fn expect_i64(&self) -> IonResult<i64>
pub fn try_into_i64(self) -> ConversionOperationResult<Element, i64>
pub fn as_usize(&self) -> Option<usize>
pub fn expect_usize(&self) -> IonResult<usize>
pub fn try_into_usize(self) -> ConversionOperationResult<Element, usize>
pub fn as_float(&self) -> Option<f64>
pub fn expect_float(&self) -> IonResult<f64>
pub fn try_into_float(self) -> ConversionOperationResult<Element, f64>
pub fn as_decimal(&self) -> Option<Decimal>
pub fn expect_decimal(&self) -> IonResult<Decimal>
pub fn try_into_decimal(self) -> ConversionOperationResult<Element, Decimal>
pub fn as_timestamp(&self) -> Option<Timestamp>
pub fn expect_timestamp(&self) -> IonResult<Timestamp>
pub fn try_into_timestamp(self) -> ConversionOperationResult<Element, Timestamp>
pub fn as_text(&self) -> Option<&str>
pub fn expect_text(&self) -> IonResult<&str>
pub fn try_into_text(self) -> ConversionOperationResult<Element, String>
pub fn as_string(&self) -> Option<&str>
pub fn expect_string(&self) -> IonResult<&str>
pub fn try_into_string(self) -> ConversionOperationResult<Element, Str>
pub fn as_symbol(&self) -> Option<&Symbol>
pub fn expect_symbol(&self) -> IonResult<&Symbol>
pub fn try_into_symbol(self) -> ConversionOperationResult<Element, Symbol>
pub fn as_bool(&self) -> Option<bool>
pub fn expect_bool(&self) -> IonResult<bool>
pub fn try_into_bool(self) -> ConversionOperationResult<Element, bool>
pub fn as_lob(&self) -> Option<&[u8]>
pub fn expect_lob(&self) -> IonResult<&[u8]>
pub fn try_into_lob(self) -> ConversionOperationResult<Element, Bytes>
pub fn as_blob(&self) -> Option<&[u8]>
pub fn expect_blob(&self) -> IonResult<&[u8]>
pub fn try_into_blob(self) -> ConversionOperationResult<Element, Bytes>
pub fn as_clob(&self) -> Option<&[u8]>
pub fn expect_clob(&self) -> IonResult<&[u8]>
pub fn try_into_clob(self) -> ConversionOperationResult<Element, Bytes>
pub fn as_sequence(&self) -> Option<&Sequence>
pub fn expect_sequence(&self) -> IonResult<&Sequence>
pub fn try_into_sequence(self) -> ConversionOperationResult<Element, Sequence>
pub fn as_list(&self) -> Option<&Sequence>
pub fn expect_list(&self) -> IonResult<&Sequence>
pub fn try_into_list(self) -> ConversionOperationResult<Element, Sequence>
pub fn as_sexp(&self) -> Option<&Sequence>
pub fn expect_sexp(&self) -> IonResult<&Sequence>
pub fn try_into_sexp(self) -> ConversionOperationResult<Element, Sequence>
pub fn as_struct(&self) -> Option<&Struct>
pub fn expect_struct(&self) -> IonResult<&Struct>
pub fn try_into_struct(self) -> ConversionOperationResult<Element, Struct>
Sourcepub fn read_first<A: AsRef<[u8]>>(data: A) -> IonResult<Option<Element>>
pub fn read_first<A: AsRef<[u8]>>(data: A) -> IonResult<Option<Element>>
Reads a single Ion Element from the provided data source.
If the data source is empty, returns Ok(None).
If the data source has at least one value, returns Ok(Some(Element)).
If the data source has invalid data, returns Err.
Sourcepub fn read_one<A: AsRef<[u8]>>(data: A) -> IonResult<Element>
pub fn read_one<A: AsRef<[u8]>>(data: A) -> IonResult<Element>
Reads a single Ion Element from the provided data source. If the input has invalid
data or does not contain at exactly one Ion value, returns Err(IonError).
Sourcepub fn read_all<A: AsRef<[u8]>>(data: A) -> IonResult<Sequence>
pub fn read_all<A: AsRef<[u8]>>(data: A) -> IonResult<Sequence>
Reads all available Elements from the provided data source.
If the input has valid data, returns Ok(Sequence).
If the input has invalid data, returns Err(IonError).
Sourcepub fn iter<'a, I: IonInput + 'a>(
source: I,
) -> IonResult<impl Iterator<Item = IonResult<Element>> + 'a>
pub fn iter<'a, I: IonInput + 'a>( source: I, ) -> IonResult<impl Iterator<Item = IonResult<Element>> + 'a>
Returns an iterator over the Elements in the provided Ion data source.
If the data source cannot be read or contains invalid Ion data, this method
will return an Err.
Sourcepub fn encode_as<E: Encoding, C: Into<WriteConfig<E>>>(
&self,
config: C,
) -> IonResult<E::Output>
pub fn encode_as<E: Encoding, C: Into<WriteConfig<E>>>( &self, config: C, ) -> IonResult<E::Output>
Encodes this element as an Ion stream with itself as the only top-level value.
If the stream’s encoding is binary Ion, returns a Vec<u8> containing the encoded bytes.
If the stream’s encoding is text Ion, returns a String containing the UTF-8 encoded text.
use ion_rs::Element;
use ion_rs::v1_0::Binary;
let ion_data = r#"{foo: "hello", bar: quux::5, baz: null, bar: false}"#;
let element_before = Element::read_one(ion_data)?;
// Encode the element as a binary Ion stream
let ion_bytes: Vec<u8> = element_before.encode_as(Binary)?;
// Read the element back from the binary stream
let element_after = Element::read_one(ion_bytes)?;
// Confirm that the value we read back is identical to the one we serialized
assert_eq!(element_before, element_after);
Sourcepub fn encode_to<E: Encoding, C: Into<WriteConfig<E>>, W: Write>(
&self,
output: W,
config: C,
) -> IonResult<W>
pub fn encode_to<E: Encoding, C: Into<WriteConfig<E>>, W: Write>( &self, output: W, config: C, ) -> IonResult<W>
Encodes this element as an Ion stream with itself as the only top-level value.
The encoded bytes are written to the provided io::Write implementation.
use ion_rs::Element;
use ion_rs::v1_0::Binary;
let ion_data = r#"{foo: "hello", bar: quux::5, baz: null, bar: false}"#;
let element_before = Element::read_one(ion_data)?;
// Encode the element as a binary Ion stream. The bytes will be written to the provided
// Vec<u8>, and the Vec<u8> will be returned when encoding is complete.
let ion_bytes: Vec<u8> = element_before.encode_to(Vec::new(), Binary)?;
// Read the element back from the binary stream
let element_after = Element::read_one(ion_bytes)?;
// Confirm that the value we read back is identical to the one we serialized
assert_eq!(element_before, element_after);
Trait Implementations§
Source§impl FromIterator<Element> for Sequence
impl FromIterator<Element> for Sequence
Source§impl FromIterator<Element> for List
impl FromIterator<Element> for List
Source§impl FromIterator<Element> for SExp
impl FromIterator<Element> for SExp
Auto Trait Implementations§
impl Freeze for Element
impl RefUnwindSafe for Element
impl Send for Element
impl Sync for Element
impl Unpin for Element
impl UnsafeUnpin for Element
impl UnwindSafe for Element
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more