Crates.io | aeon_derive |
lib.rs | aeon_derive |
version | 0.2.0 |
source | src |
created_at | 2020-10-19 20:17:41.301058 |
updated_at | 2020-10-19 20:17:41.301058 |
description | Derive macros for package 'aeon'. |
homepage | |
repository | https://github.com/Szune/aeon-rs |
max_upload_size | |
id | 303088 |
size | 12,651 |
⚠ Works, but isn't production ready
Awfully exciting object notation
@server(id, name, ip, port)
servers: [
server(1, "test", [127,0,0,1], 7171),
server(2, "production", [0,0,0,0], 8080),
]
/* using derive macro */
use aeon::convert_panic::*;
use aeon::*;
use aeon_derive::{Deserialize,Serialize};
#[derive(Serialize, Deserialize, Debug)]
pub struct Heuristic{
pub value: String,
pub weight: i32,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct WithHeuristics {
pub something: Vec<Heuristic>,
pub else: bool,
}
// deserialize:
let heuristics = WithHeuristics::from_aeon(some aeon string here);
// serialize:
println!("{}", WithHeuristics::to_aeon(&heuristics));
// would print something similar to:
/*
@heuristic(value, weight)
something: [
heuristic("some_name", 10),
heuristic("some_other_name", 19),
]
else: false
*/
/* typing it out manually */
use aeon::*;
use aeon::convert_panic::*; // there's also aeon::convert::* if you prefer Option<T> over panics
let servers = aeon::deserialize(data).get("servers").list();
println!("{:?}", servers);
// there's also get_path("path/to/value") functions
Comments start with a '#' symbol.
# comments are allowed on their own lines
thing: "text" # and at the end of lines
Comments are not serialized when performing deserializing -> serializing, this may change in the future
Macros are parsed as HashMap<String, AeonValue>.
Macros start with an '@' symbol, followed by an identifier and a list of arguments.
E.g. @identifier(argument1, argument2, argument3)
Macros need to be defined before they are used, preferably at the start of the file, before any variables.
Macro identifiers can also be used as variable identifiers.