Crates.io | simpleml_macro |
lib.rs | simpleml_macro |
version | 2.0.0 |
source | src |
created_at | 2024-04-07 19:50:16.074485 |
updated_at | 2024-10-27 22:45:40.121957 |
description | A macro for placing SimpleML content directly into Rust source code. |
homepage | |
repository | https://github.com/mr-adult/SimpleML |
max_upload_size | |
id | 1199473 |
size | 17,893 |
This crate is an extension of simpleml. It creates an "sml" macro to allow you to declare SML-based config within your code.
Updating the dependency on tree_iterators_rs to version 2.0 for better performance. This is a breaking change and all consumers will need to update their code to get these performance benefits. If performance is not a problem for you, there is no reason to switch.
Fixes a macro panic when null values are used
In order to use this macro, add the following to your Cargo.toml. NOTE: This macro requires the nightly compiler for the proc_macro_span feature.
[dependencies]
tree_iterators_rs = "2.0"
simpleml = "2.0"
simpleml_macro = "2.0"
Once you have these dependencies in place, simply add a using for the macro, and use it in your code. As an example, let's convert the following in-line declaration of the SML data structure over to using the macro. This example comes from the README.md file of simpleml.
use tree_iterators_rs::prelude::*;
use simpleml::{SMLWriter, SMLElement, SMLAttribute};
let my_sml_values = TreeNode {
value: SMLElement {
name: "Configuration",
attributes: Vec::with_capacity(0),
},
children: vec![
TreeNode {
value: SMLElement {
name: "Video",
attributes: vec![
SMLAttribute {
name: "Resolution",
values: vec![Some("1280"), Some("720")],
},
SMLAttribute {
name: "RefreshRate",
values: vec![Some("60")],
},
SMLAttribute {
name: "Fullscreen",
values: vec![Some("true")],
},
],
},
children: Vec::new(),
},
TreeNode {
value: SMLElement {
name: "Audio",
attributes: vec![
SMLAttribute {
name: "Volume",
values: vec![Some("100")],
},
SMLAttribute {
name: "Music",
values: vec![Some("80")],
},
],
},
children: Vec::new(),
},
TreeNode {
value: SMLElement {
name: "Player",
attributes: vec![SMLAttribute {
name: "Name",
values: vec![Some("Hero 123")],
}],
},
children: Vec::new(),
},
],
};
use simpleml_macro::sml;
let my_sml_values = sml!{
Configuration
Video
Resolution 1280 720
RefreshRate 60
Fullscreen true
my_custom_end_keyword
Audio
Volume 100
Music 80
my_custom_end_keyword
Player
Name "Hero 123"
my_custom_end_keyword
my_custom_end_keyword
};