Coder Social home page Coder Social logo

ion-rust's Introduction

Amazon Ion Rust

Crate Docs License CI Build codecov

A Rust implementation of the Amazon Ion data format.

Example

For more information, please see our official documentation.

use ion_rs::{Element, IonResult, IonType, ion_seq};

fn main() -> IonResult<()> {

    // Read a single value from a string/slice/Vec
    let element = Element::read_one("\"Hello, world!\"")?;
    let text = element.expect_string()?;
    assert_eq!(text, "Hello, world!");

    // Read a series of values from a string/slice/Vec
    let elements = Element::read_all("1 2 3")?;
    let mut sum = 0;
    for element in elements {
        sum += element.expect_i64()?;
    }
    assert_eq!(sum, 6);

    // Iterate over values in a file
    let ion_file = std::fs::File::open("/foo/bar/baz.ion").unwrap();
    for element in Element::iter(ion_file)? {
        println!("{}", element?)
    }
    
    // Construct a sequence of Ion elements from Rust values
    let values = ion_seq!(
        "foo",
        Timestamp::with_ymd(2016, 5, 11).build(),
        3.1416f64,
        true
    );

    // Write values to a buffer in generously-spaced text
    let mut text_buffer: Vec<u8> = Vec::new();
    Element::write_all_as(&values, Format::Text(TextKind::Pretty), &mut text_buffer)?;
    assert_eq!(values, Element::read_all(text_buffer)?);

    // Write values to a buffer in compact binary
    let mut binary_buffer: Vec<u8> = Vec::new();
    Element::write_all_as(&values, Format::Binary, &mut binary_buffer)?;
    assert_eq!(values, Element::read_all(binary_buffer)?);
    
    Ok(())
}

Experimental features

The ion_rs library has a number of features that users can opt into. While the following features are complete and well-tested, their APIs are not stable and are subject to change without notice between minor versions of the library.

  1. experimental-ion-hash, an implementation of Ion Hash.
  2. experimental-reader, a streaming reader API.
  3. experimental-writer, a streaming writer API.

Features that are defined in Cargo.toml but not listed above have not been thoroughly tested.

Development

This project uses a submodule to pull in Ion Tests and Ion Hash Tests. The easiest way to pull everything in is to clone the repository recursively:

$ git clone --recursive https://github.com/amazon-ion/ion-rust

You can also initialize the submodules as follows:

$ git submodule update --init --recursive

Building the project:

$ cargo build --all-features

Running all tests for ion-rust:

$ cargo test --all-features

Our continuous integration builds/tests, checks formatting, builds all API docs including private, and clippy linting, you will likely want to check most of these to avoid having to wait until the CI finds it:

$ ./clean-rebuild.sh

ion-rust's People

Contributors

zslayton avatar almann avatar desaikd avatar marcbowes avatar popematt avatar nirosys avatar jobarr-amzn avatar jpeddicord avatar therapon avatar jpschorr avatar rmarrowstone avatar rgantt avatar sadderchris avatar jnicholls avatar plasmaintec avatar infinite-blue-1042 avatar tommy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.