Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,41 @@ jobs:
- name: Run example
working-directory: ./js
run: npm run example

test-rust:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable

- name: Cache cargo dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
rust/target/
key: ${{ runner.os }}-cargo-${{ hashFiles('rust/Cargo.lock') }}

- name: Run tests
working-directory: ./rust
run: cargo test --verbose

- name: Run example
working-directory: ./rust
run: cargo run --example basic_usage

- name: Check formatting
working-directory: ./rust
run: cargo fmt --check

- name: Run clippy
working-directory: ./rust
run: cargo clippy -- -D warnings
43 changes: 40 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@
[![Tests](https://github.com/link-foundation/lino-objects-codec/actions/workflows/test.yml/badge.svg)](https://github.com/link-foundation/lino-objects-codec/actions/workflows/test.yml)
[![Python Version](https://img.shields.io/pypi/pyversions/lino-objects-codec.svg)](https://pypi.org/project/lino-objects-codec/)

Universal serialization library to encode/decode objects to/from Links Notation format. Available in both **Python** and **JavaScript** with identical functionality and API design.
Universal serialization library to encode/decode objects to/from Links Notation format. Available in **Python**, **JavaScript**, and **Rust** with identical functionality and API design.

## 🌍 Multi-Language Support

This library provides universal serialization and deserialization with built-in support for circular references and complex object graphs in:

- **[Python](python/)** - Full implementation for Python 3.8+
- **[JavaScript](js/)** - Full implementation for Node.js 18+
- **[Rust](rust/)** - Full implementation for Rust 1.70+

Both implementations share the same design philosophy and provide feature parity.
All implementations share the same design philosophy and provide feature parity.

## Features

- **Universal Serialization**: Encode objects to Links Notation format
- **Type Support**: Handle all common types in each language:
- **Python**: `None`, `bool`, `int`, `float`, `str`, `list`, `dict`
- **JavaScript**: `null`, `undefined`, `boolean`, `number`, `string`, `Array`, `Object`
- **Rust**: `LinoValue` enum with `Null`, `Bool`, `Int`, `Float`, `String`, `Array`, `Object`
- Special float/number values: `NaN`, `Infinity`, `-Infinity`
- **Circular References**: Automatically detect and preserve circular references
- **Object Identity**: Maintain object identity for shared references
Expand Down Expand Up @@ -63,6 +65,27 @@ const decoded = decode(encoded);
console.log(JSON.stringify(decoded) === JSON.stringify(data)); // true
```

### Rust

```toml
[dependencies]
lino-objects-codec = "0.1"
```

```rust
use lino_objects_codec::{encode, decode, LinoValue};

// Encode and decode
let data = LinoValue::object([
("name", LinoValue::String("Alice".to_string())),
("age", LinoValue::Int(30)),
("active", LinoValue::Bool(true)),
]);
let encoded = encode(&data);
let decoded = decode(&encoded).unwrap();
assert_eq!(decoded, data);
```

## Repository Structure

```
Expand All @@ -77,6 +100,10 @@ console.log(JSON.stringify(decoded) === JSON.stringify(data)); // true
│ ├── tests/ # Test suite
│ ├── examples/ # Usage examples
│ └── README.md # JavaScript-specific docs
├── rust/ # Rust implementation
│ ├── src/ # Source code
│ ├── examples/ # Usage examples
│ └── README.md # Rust-specific docs
└── README.md # This file
```

Expand All @@ -86,10 +113,11 @@ For detailed documentation, API reference, and examples, see:

- **[Python Documentation](python/README.md)**
- **[JavaScript Documentation](js/README.md)**
- **[Rust Documentation](rust/README.md)**

## Usage Examples

Both implementations support the same features with language-appropriate syntax:
All implementations support the same features with language-appropriate syntax:

### Circular References

Expand Down Expand Up @@ -181,6 +209,14 @@ npm test
npm run example
```

### Rust

```bash
cd rust
cargo test
cargo run --example basic_usage
```

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.
Expand All @@ -203,6 +239,7 @@ This project is licensed under the Unlicense - see the [LICENSE](LICENSE) file f
- [Links Notation Specification](https://github.com/link-foundation/links-notation)
- [PyPI Package](https://pypi.org/project/lino-objects-codec/) (Python)
- [npm Package](https://www.npmjs.com/package/lino-objects-codec/) (JavaScript)
- [crates.io Package](https://crates.io/crates/lino-objects-codec/) (Rust)

## Acknowledgments

Expand Down
1 change: 1 addition & 0 deletions rust/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
41 changes: 41 additions & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "lino-objects-codec"
version = "0.1.0"
edition = "2021"
rust-version = "1.70"
description = "A library to encode/decode objects to/from links notation"
license = "Unlicense"
repository = "https://github.com/link-foundation/lino-objects-codec"
documentation = "https://docs.rs/lino-objects-codec"
readme = "README.md"
keywords = ["links-notation", "serialization", "codec", "object-graph", "circular-references"]
categories = ["encoding", "parser-implementations"]

[dependencies]
links-notation = "0.13.0"
base64 = "0.22"

[dev-dependencies]
Loading