Crates.io | rust_erl_ext |
lib.rs | rust_erl_ext |
version | 0.2.1 |
source | src |
created_at | 2015-01-12 16:14:13.506596 |
updated_at | 2015-12-11 23:56:40.231265 |
description | Erlang external term format codec. |
homepage | |
repository | https://github.com/seriyps/rust-erl-ext |
max_upload_size | |
id | 773 |
size | 105,322 |
Erlang external term format parser/serializer for Rust.
Decoding
extern crate erl_ext;
use erl_ext::Decoder;
fn main() {
let mut decoder = Decoder::new(&mut io::stdin());
assert!(true == decoder.read_prelude().unwrap());
println!("{}", decoder.decode_term().unwrap());
}
Encoding
extern crate erl_ext;
use erl_ext::{Eterm, Encoder};
fn main() {
let term = Eterm::List(vec!(Eterm::SmallInteger(1),
Eterm::Integer(1000000),
Eterm::Nil));
// this combination of options make it compatible with erlang:term_to_binary/1
let utf8_atoms = false;
let small_atoms = false;
let fair_new_fun = true;
let mut encoder = Encoder::new(&mut io::stdout(),
utf8_atoms, small_atoms, fair_new_fun);
encoder.write_prelude();
encoder.encode_term(term);
}
More examples are in examples
directory.
Types (all Erlang 17.1 types are supported):
SmallInteger (u8) : 0..255
Integer (i32) : integer()
Float (f64) : float()
Atom (String) : atom()
Reference : reference()
erlang:make_ref/0
Port : port()
eg, socket or raw file or erlang:open_port/2
Pid : pid()
Tuple (Vec<Eterm>
) : { any() }
Map (Vec<(Eterm, Eterm)>
) : #{any() := any()}
Nil : []
String (Vec<u8>
) : [0..255]
List (Vec<Eterm>
) : [ any() ]
Binary (Vec<u8>
) : binary()
BigNum (BigInt
) : integer() > i32
Fun : fun(..) -> ... end.
- deprecated variant
NewFun : fun(..) -> ... end.
Export : fun my_mod:my_fun/1
BitBinary : <<128, 128:4>>
serialize::Decoder
and serialize::Encoder
implementations (not so easy for containers)