MCPcopy Index your code
hub / github.com/amazon-ion/ion-rust

github.com/amazon-ion/ion-rust @v1.0.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.0.0 ↗ · + Follow
3,821 symbols 11,508 edges 182 files 847 documented · 22%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Amazon Ion Rust

Crate Docs License CI Build codecov

A Rust implementation of the Amazon Ion data format.

Example

For more information, please see the documentation.

use crate::{ion_seq, Element, IonResult, Timestamp};

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 String using generously-spaced text
    let text_ion: String = values.encode_as(v1_0::Text.with_format(TextFormat::Pretty))?;
    assert_eq!(values, Element::read_all(text_ion)?);

    // Write values to a buffer in compact binary
    let binary_buffer: Vec<u8> = values.encode_as(v1_0::Binary)?;
    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-reader-writer, a streaming reader and writer API.
  2. experimental-tooling-apis, APIs for accessing the encoding-level details of the stream.
  3. experimental-serde, a serde serializer and deserializer.
  4. experimental-ion-hash, an implementation of Ion Hash.

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

Extension points exported contracts — how you extend this code

AsRawSymbolRef (Interface)
Implemented by types that can be viewed as a [RawSymbolRef] without allocations. [7 implementers]
src/raw_symbol_ref.rs
IonInput (Interface)
Types that can be used as a source of Ion data. This trait is sealed and cannot be implemented outside of this crate. I [7 …
src/lazy/streaming_raw_reader.rs
IonDataOrd (Interface)
Trait used for delegating [Ord] and [PartialOrd] in [IonData](crate::IonData). Implementations of [IonDataOrd] must be c [14 …
src/ion_data/ion_ord.rs
AsSymbolRef (Interface)
Allows a `SymbolRef` to be constructed from a source value. This enables non-symbol types to be viewed as a symbol with [3 …
src/symbol_ref.rs
Catalog (Interface)
A Catalog is a collection of Shared Symbol Tables. For more information about the concept of a catalog, see [the `symbol [2 …
src/catalog.rs
SmallestFloatRepr (Interface)
Finds the smallest valid Ion encoding for a given floating point value. [2 implementers]
src/types/float.rs
IonFailure (Interface)
Crate-visible convenience methods for constructing error variants and wrapping them in the appropriate type: IonResult<T [2 …
src/result/mod.rs
TestReporter (Interface)
Implementable trait for providing different output formats for the test results report. [2 implementers]
tests/conformance.rs

Core symbols most depended-on inside this repo

expect
called by 178
src/lazy/value.rs
get_ref
called by 99
src/lazy/expanded/mod.rs
close
called by 97
src/lazy/encoder/writer.rs
clone
called by 94
src/types/symbol.rs
build
called by 92
src/types/timestamp.rs
push
called by 90
src/lazy/expanded/macro_evaluator.rs
value
called by 87
src/lazy/expanded/struct.rs
len
called by 86
src/lazy/expanded/template.rs

Shape

Method 2,420
Function 832
Class 373
Enum 120
Interface 76

Languages

Rust100%

Modules by API surface

src/lazy/expanded/macro_evaluator.rs190 symbols
src/lazy/text/buffer.rs176 symbols
src/element/mod.rs133 symbols
src/types/timestamp.rs123 symbols
src/lazy/expanded/template.rs110 symbols
src/lazy/expanded/mod.rs91 symbols
src/lazy/binary/raw/v1_1/binary_buffer.rs80 symbols
src/lazy/encoder/writer.rs79 symbols
src/lazy/any_encoding.rs76 symbols
src/lazy/expanded/compiler.rs69 symbols
src/lazy/encoder/binary/v1_1/value_writer.rs64 symbols
src/lazy/binary/raw/value.rs63 symbols

For agents

$ claude mcp add ion-rust \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact