lperlaki / astr-rs Goto Github PK
View Code? Open in Web Editor NEWHome Page: https://crates.io/crates/astr
Home Page: https://crates.io/crates/astr
The primary goal of this crate seems to be to avoid needless allocations for small constant-sized strings. Some of these strings can include IDs, UUIDs, PINs, MAC addresses, RGB hex colors etc. which may have a compact in-memory representation and a less compact string representation whose length is strictly constant (i.e. a UUID will always be 36 bytes long in string form). The "compact" representation often comes with a Debug
or Display
implementation which is solely responsible for the conversion.
I think it would be convenient to have a way to build an AStr
from any type that implements Display
, given an expected total length. If the Display
implementation writes too few or too much characters, an error is returned instead.
The additional constructor could look something like AStr::from_fmt(fmt: &dyn std::fmt::Display)
. An equivalent method for the Debug
trait is superfluous as calling format_args!("{something:?}")
will return a Display
able Arguments<'_>
instance that calls the Debug
implementation of "something". With a macro as explained below, you wouldn't even call this function manually most of the time.
I have a working implementation in one of my projects, which also comes with a format_astr!()
macro to build AStr
s even faster. I would love to open a PR, but if you're interested, I would like guidance on the exact constructor name and signature that you would like, whether a format_astr!
macro is in-scope for this PR, and whether or not the macro should take an optional parameter to specify the expected length (or else, type inference would do the job alone).
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.