Cherries the expression logging library
Cherries is a crate that does expression logging as json structure.
Usage
cherries requires rustc 1.37.0 or later. Add this to your Cargo.toml
:
cherries = "0.2.2"
Labeling
You can label to leaf with builder or rename with labeled
method.
extern crate cherries;
use ;
Validation
Validation utilities are in module cherries::validate
.
- Validate: Trait that provides extension method
validate
toCherry<T>
. - ValidateChain: Struct that allows to chain
validate
and providesinto_result
. - Error: Information struct for validation errors.
extern crate cherries;
use ;
use ;
Get json string
You can get expression tree with json structure using Cherries::to_json()
.
extern crate cherries;
use ;
use ;
Output:
{
"label":"(mul)",
"value":15,
"unit":"dimensionless",
"subexpr":[
{
"label":"(add)",
"value":5,
"unit":"dimensionless",
"subexpr":[
{
"label":"a",
"value":2,
"unit":"dimensionless"
},
{
"label":"b",
"value":3,
"unit":"dimensionless"
}
]
},
{
"label":"(sub)",
"value":3,
"unit":"dimensionless",
"subexpr":[
{
"label":"c",
"value":4,
"unit":"dimensionless"
},
{
"label":"d",
"value":1,
"unit":"dimensionless"
}
]
}
]
}
Mapping
For example, show you how to use cherries with uom crate (units of measurement).
Let's applying method floor
with turbofish using map
.
extern crate cherries;
use ;
use ;
use *;
use ;
Output:
{
"label":"floor",
"value":2,
"unit":"m^1",
"subexpr":[
{
"label":"x",
"value":2.1,
"unit":"m^1"
}
]
}
License
Licensed under MIT LICENSE.