[][src]Trait ion_rs::cursor::Cursor

pub trait Cursor {
    type DataSource: IonDataSource;
    pub fn ion_version(&self) -> (u8, u8);
pub fn next(&mut self) -> IonResult<Option<StreamItem>>;
pub fn ion_type(&self) -> Option<IonType>;
pub fn is_null(&self) -> bool;
pub fn annotation_ids(&self) -> &[SymbolId];
pub fn field_id(&self) -> Option<SymbolId>;
pub fn read_null(&mut self) -> IonResult<Option<IonType>>;
pub fn read_bool(&mut self) -> IonResult<Option<bool>>;
pub fn read_i64(&mut self) -> IonResult<Option<i64>>;
pub fn read_f32(&mut self) -> IonResult<Option<f32>>;
pub fn read_f64(&mut self) -> IonResult<Option<f64>>;
pub fn read_big_decimal(&mut self) -> IonResult<Option<BigDecimal>>;
pub fn read_string(&mut self) -> IonResult<Option<String>>;
pub fn string_ref_map<F, T>(&mut self, f: F) -> IonResult<Option<T>>
    where
        F: FnOnce(&str) -> T
;
pub fn string_bytes_map<F, T>(&mut self, f: F) -> IonResult<Option<T>>
    where
        F: FnOnce(&[u8]) -> T
;
pub fn read_symbol_id(&mut self) -> IonResult<Option<SymbolId>>;
pub fn read_blob_bytes(&mut self) -> IonResult<Option<Vec<u8>>>;
pub fn blob_ref_map<F, U>(&mut self, f: F) -> IonResult<Option<U>>
    where
        F: FnOnce(&[u8]) -> U
;
pub fn read_clob_bytes(&mut self) -> IonResult<Option<Vec<u8>>>;
pub fn clob_ref_map<F, U>(&mut self, f: F) -> IonResult<Option<U>>
    where
        F: FnOnce(&[u8]) -> U
;
pub fn read_datetime(&mut self) -> IonResult<Option<DateTime<FixedOffset>>>;
pub fn step_in(&mut self) -> IonResult<()>;
pub fn step_out(&mut self) -> IonResult<()>;
pub fn depth(&self) -> usize; }

This trait captures the format-agnostic parser functionality needed to navigate within an Ion stream and read the values encountered into native Rust data types.

Cursor implementations are not expected to interpret symbol table declarations, resolve symbol IDs into text, or otherwise interpret system-level constructs for use at a user level.

Once a value has successfully been read from the stream using one of the read_* functions, calling that function again may return an Err. This is left to the discretion of the implementor.

Associated Types

Loading content...

Required methods

pub fn ion_version(&self) -> (u8, u8)[src]

Returns the (major, minor) version of the Ion stream being read. If ion_version is called before an Ion Version Marker has been read, the version (1, 0) will be returned.

pub fn next(&mut self) -> IonResult<Option<StreamItem>>[src]

Attempts to advance the cursor to the next value in the stream at the current depth. If no value is encountered, returns None; otherwise, returns the Ion type of the next value.

pub fn ion_type(&self) -> Option<IonType>[src]

Returns the Ion type of the value currently positioned under the cursor. If the cursor is not positioned over a value, returns None.

pub fn is_null(&self) -> bool[src]

Returns true if the current value is a null of any type; otherwise, returns false.

pub fn annotation_ids(&self) -> &[SymbolId][src]

Returns a slice containing all of the annotation symbol IDs for the current value. If there is no current value, returns an empty slice.

pub fn field_id(&self) -> Option<SymbolId>[src]

If the current value is a field within a struct, returns the symbol ID of that field's name; otherwise, returns None.

pub fn read_null(&mut self) -> IonResult<Option<IonType>>[src]

If the current value is a null, returns the Ion type of the null; otherwise, returns None.

pub fn read_bool(&mut self) -> IonResult<Option<bool>>[src]

If the current value is a boolean, returns its value as a bool; otherwise, returns None.

pub fn read_i64(&mut self) -> IonResult<Option<i64>>[src]

If the current value is an integer, returns its value as an i64; otherwise, returns None.

pub fn read_f32(&mut self) -> IonResult<Option<f32>>[src]

If the current value is a float, returns its value as an f32; otherwise, returns None.

pub fn read_f64(&mut self) -> IonResult<Option<f64>>[src]

If the current value is a float, returns its value as an f64; otherwise, returns None.

pub fn read_big_decimal(&mut self) -> IonResult<Option<BigDecimal>>[src]

If the current value is a decimal, returns its value as an BigDecimal; otherwise, returns None.

pub fn read_string(&mut self) -> IonResult<Option<String>>[src]

If the current value is a string, returns its value as a String; otherwise, returns None.

pub fn string_ref_map<F, T>(&mut self, f: F) -> IonResult<Option<T>> where
    F: FnOnce(&str) -> T, 
[src]

Runs the provided closure, passing in a reference to the string to be read and allowing a calculated value of any type to be returned. When possible, string_ref_map will pass a reference directly to the bytes in the input buffer rather than allocating a new string.

pub fn string_bytes_map<F, T>(&mut self, f: F) -> IonResult<Option<T>> where
    F: FnOnce(&[u8]) -> T, 
[src]

Runs the provided closure, passing in a reference to the unparsed, unvalidated bytes of the string to be read and allowing a calculated value of any type to be returned. When possible, string_bytes_map will pass a reference directly to the bytes in the input buffer rather than copying the data.

This function can be used to avoid the cost of utf8 validation for strings that are not yet known to be of interest.

pub fn read_symbol_id(&mut self) -> IonResult<Option<SymbolId>>[src]

If the current value is a symbol, returns its value as a SymbolId; otherwise, returns None.

pub fn read_blob_bytes(&mut self) -> IonResult<Option<Vec<u8>>>[src]

If the current value is a blob, returns its value as a Vec; otherwise, returns None.

pub fn blob_ref_map<F, U>(&mut self, f: F) -> IonResult<Option<U>> where
    F: FnOnce(&[u8]) -> U, 
[src]

Runs the provided closure, passing in a reference to the blob to be read and allowing a calculated value of any type to be returned. When possible, blob_ref_map will pass a reference directly to the bytes in the input buffer rather than allocating a new array.

pub fn read_clob_bytes(&mut self) -> IonResult<Option<Vec<u8>>>[src]

If the current value is a clob, returns its value as a Vec; otherwise, returns None.

pub fn clob_ref_map<F, U>(&mut self, f: F) -> IonResult<Option<U>> where
    F: FnOnce(&[u8]) -> U, 
[src]

Runs the provided closure, passing in a reference to the clob to be read and allowing a calculated value of any type to be returned. When possible, clob_ref_map will pass a reference directly to the bytes in the input buffer rather than allocating a new array.

pub fn read_datetime(&mut self) -> IonResult<Option<DateTime<FixedOffset>>>[src]

If the current value is a timestamp, returns its value as a DateTime; otherwise, returns None.

pub fn step_in(&mut self) -> IonResult<()>[src]

If the current value is a container (i.e. a struct, list, or s-expression), positions the cursor at the beginning of that container's sequence of child values. If the current value is not a container, returns Err.

pub fn step_out(&mut self) -> IonResult<()>[src]

Positions the cursor at the end of the container currently being traversed. Calling next() will position the cursor over the value that follows the container. If the cursor is not in a container (i.e. it is already at the top level), returns Err.

pub fn depth(&self) -> usize[src]

Loading content...

Implementors

impl<R: IonDataSource> Cursor for BinaryIonCursor<R>[src]

type DataSource = R

Loading content...