You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In order to keep compile times in check and rust-analyzer snappy, I've resorted to spamming .boxed() everywhere I go. This, combined with the resultant frequent requirement of .clone(), drives the signal-to-noise ratio of a parser off a cliff. If only there was a better way...
A better way?
Provide a sibling method to .boxed(), .leak(). It boxes the parser, leaks it, and returns a dyn reference. Such a reference can be used any number of times without extra noise or worries about lifetimes.
Many users can just s/boxed/leak/ and remove .clone()s, because their parser is constructed once and alive for the entire duration of their application anyway. Otherwise, they can stuff their parser in a OnceLock or something (note: I don't really know how to do this or if it's even possible).
Here's the implementation I'm using in my application:
Add a default feature, concrete-types. Turning it off makes the return type of almost every primitive and combinator a dyn reference. Users can disable this feature for debug builds to keep rust-analyzer and cargo check happy, only occasionally sprinkling in .boxed() or .leak() to keep release builds acceptably fast, or disable it entirely for simplicity at the cost of performance.
I'm not really sure about the possibility, practicality, or usability of this, but if it works it's probably as close as one can get to a seamless experience without tooling improvements or new language features.
The text was updated successfully, but these errors were encountered:
In order to keep compile times in check and rust-analyzer snappy, I've resorted to spamming
.boxed()
everywhere I go. This, combined with the resultant frequent requirement of.clone()
, drives the signal-to-noise ratio of a parser off a cliff. If only there was a better way...A better way?
Provide a sibling method to
.boxed()
,.leak()
. It boxes the parser, leaks it, and returns a dyn reference. Such a reference can be used any number of times without extra noise or worries about lifetimes.Many users can just
s/boxed/leak/
and remove.clone()
s, because their parser is constructed once and alive for the entire duration of their application anyway. Otherwise, they can stuff their parser in aOnceLock
or something (note: I don't really know how to do this or if it's even possible).Here's the implementation I'm using in my application:
A betterer way?
Add a default feature,
concrete-types
. Turning it off makes the return type of almost every primitive and combinator a dyn reference. Users can disable this feature for debug builds to keep rust-analyzer and cargo check happy, only occasionally sprinkling in.boxed()
or.leak()
to keep release builds acceptably fast, or disable it entirely for simplicity at the cost of performance.I'm not really sure about the possibility, practicality, or usability of this, but if it works it's probably as close as one can get to a seamless experience without tooling improvements or new language features.
The text was updated successfully, but these errors were encountered: