hukumka / reformation Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Parsing complex struct could negatively impact performance.
Lets take a look at example:
Assuming we have to parse logs of following format:
[{datetime}:{process_uuid}] {message}
With typical usage: Filter out interesting messages, then process time deltas between then, aggregating by process uuid.
Where are two ways to define struct to parse such a line:
#[derive(Reformation)]
#[reformation("[{header}] {message}", no_regex=true)]
struct LogLine {
header: Header,
message: Message,
}
#[derive(Reformation)]
#[reformation("{datetime}:{process_uuid}")]
struct Header {
datetime: CustomDatetime,
process_uuid: UUID,
}
#[reformation("[{header}] {message}", no_regex=true)]
struct LogLine {
#[reformation("[^\[]*")]
header: String,
message: Message,
}
Problem with first one is that it is less performant then the second, if we need too look at header only 1 out of 10 lines.
Problem with second one is that types become harder to follow, and code wanting to use header would need to execute Header::parse manually.
The way I see solution to this problem, is to introduce wrapper LazyParse
, which will allow to define struct like this:
#[derive(Reformation)]
#[reformation("[{header}] {message}", no_regex=true)]
struct LogLine {
#[reformation("[^\[]*")]
header: LazyParse<Header>,
message: Message,
}
Internally, LazyParse would be implemented as
enum LazyParse<T> {
Raw(String),
Parsed(T),
}
And parsing from string would only create raw version, while actual value would be parsed only then first requested.
LazyParse
counterpart that contains &'a str
Correct me if I'm wrong, but it doesn't seem that this crate supports enum
s in any way. Is this planned on being supported?
Example:
#[derive(Reformation)]
#[reformation("$", no_regex=true)]
Dollar{}
Expected regex:
r"\$"
Produced regex:
r"$"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.