lino-objects-codec (Rust)
Rust implementation of the Links Notation Objects Codec - a universal serialization library to encode/decode objects to/from Links Notation format.
Installation
Add to your Cargo.toml:
[]
= "0.1"
Features
- Universal Serialization: Encode objects to Links Notation format
- Type Support: Handle all common types:
null(Null)bool(Bool)int(Int - 64-bit signed)float(Float - 64-bit, including NaN, Infinity, -Infinity)str(String)array(Array)object(Object)
- Special Float Values: Full support for NaN, Infinity, -Infinity (which are not valid JSON)
- Circular References: Detect and preserve circular references via object IDs
- Object Identity: Maintain object identity for shared references
- UTF-8 Support: Full Unicode string support using base64 encoding
- Simple API: Easy-to-use
encode()anddecode()functions
Quick Start
use ;
// Create an object
let data = object;
// Encode to Links Notation
let encoded = encode;
println!;
// Decode back
let decoded = decode.unwrap;
assert_eq!;
API Reference
Types
LinoValue
The main value type that can represent any serializable value:
Helper methods:
LinoValue::object(iter)- Create an object from key-value pairsLinoValue::array(iter)- Create an array from valuesis_null(),as_bool(),as_int(),as_float(),as_str(),as_array(),as_object()- Type checking and extractionget(key)- Get a value from an object by keyget_index(index)- Get a value from an array by index
CodecError
Error type for codec operations:
Functions
encode(value: &LinoValue) -> String
Encode a value to Links Notation format.
let value = Int;
let encoded = encode;
assert_eq!;
decode(notation: &str) -> Result<LinoValue, CodecError>
Decode Links Notation format to a value.
let decoded = decode.unwrap;
assert_eq!;
ObjectCodec
For advanced use cases, you can create your own codec instance:
use ObjectCodec;
let mut codec = new;
let encoded = codec.encode;
let decoded = codec.decode?;
Usage Examples
Basic Types
use ;
// Null
let null = Null;
assert_eq!;
// Boolean
let bool_val = Bool;
assert_eq!;
// Integer
let int_val = Int;
assert_eq!;
// Float
let float_val = Float;
assert!;
// Special floats
let inf = Float;
assert_eq!;
let nan = Float;
assert_eq!;
// String (base64 encoded)
let str_val = String;
assert_eq!;
Collections
use ;
// Array
let array = array;
let encoded = encode;
let decoded = decode.unwrap;
assert_eq!;
// Object
let obj = object;
let encoded = encode;
let decoded = decode.unwrap;
assert_eq!;
Nested Structures
use ;
let data = object;
let encoded = encode;
let decoded = decode.unwrap;
// Access nested values
let users = decoded.get.unwrap.as_array.unwrap;
assert_eq!;
From Traits
LinoValue implements From for common Rust types:
use LinoValue;
let null: LinoValue = .into;
let bool_val: LinoValue = true.into;
let int_val: LinoValue = 42i64.into;
let float_val: LinoValue = 3.14f64.into;
let str_val: LinoValue = "hello".into;
let vec_val: LinoValue = vec!.into;
let opt_val: LinoValue = Some.into;
let none_val: LinoValue = None::.into;
How It Works
The codec encodes values using the Links Notation format:
- Basic types:
(int 42),(str aGVsbG8=),(bool true) - Strings are base64-encoded to handle special characters and newlines
- Arrays:
(array (int 1) (int 2) (int 3)) - Objects:
(object ((str a2V5) (int 42)) ...) - Special floats:
(float NaN),(float Infinity),(float -Infinity)
For structures with shared references or circular references, the codec uses object IDs:
- Format:
(obj_0: array ...)or(obj_0: object ...) - References:
obj_0
Development
# Run tests
# Run example
# Build documentation
License
This project is licensed under the Unlicense - see the LICENSE file for details.