flmacro
Macros for the use in fledger.
platrform_async_trait
This holds the macro for defining an async_trait either with or without the
Send trait.
You can use it like this:
Depending on wasm or unix, it will either remove or keep the Send trait.
proc_macro_derive(AsU256)
This allows to use tuple struct, or a newtype struct, based on U256, to export
all methods from U256.
Instead of using a type definition, which is not unique and can be replaced by any
of the other types, tuple structs allow for more type safety.
You can use it like this:
;
And now you can have MyID::rnd() and all the other methods from U256.
proc_macro_derive(VersionedSerde, attributes(versions, serde))
To store configuration and other data in different version, you can use this derive macro:
use Bytes;
use VersionedSerde;
use ;
use ;
It will do the following:
- create a copy of the
struct Configasstruct ConfigV3with appropriateFROMimplementations - create a
ConfigVersionenum with all configs in it - implement
serde::Serializeandserde::DeserializeonConfigwhich will- wrap
Configin theConfigVersion - serialize the
ConfigVersion, or - deserialize the
ConfigVersionand convert it toConfig
- wrap
This allows you to use any serde implementation to store any version of your structure, and retrieve always the latest version:
Usage of serde_as and others
To allow usage of serde_as, the VersionedSerde also defines the serde attribute.
However, VersionedSerde does not use it itself.
Usage of a new configuration structure
When you start with a new configuration structure, the versions can be omitted:
When converting this using serde, it will store it as V1.
So whenever you create a new version, you can add it with
a converter to the latest structure:
target_send
This macro does two things:
- for traits, it creates a version of the trait with
Boxat the end, and it adds+ Sendfor non-wasm targets - for types, it adds
+ Sendthree characters from the end of the type in rust-macro-format
So the following
type SomethingElse<T> = ;
Will be translated to:
type SomethingBox<T> =
type SomethingElse<T> = ;
with $SEND either an empty string for wasm targets, or + Send for non-wasm targets.
Specifically the handling of the type is very ugly, as it converts the type to a string,
adds conditionally + Send three characters from the end, and parses the resulting string.
Kids, don't do this at home...