Crates.io | constructivist |
lib.rs | constructivist |
version | 0.3.0 |
source | src |
created_at | 2023-10-05 15:59:11.074824 |
updated_at | 2023-12-12 10:04:11.848579 |
description | Simplify the construction of structured data. |
homepage | https://github.com/polako-rs/constructivism/tree/main/crates/constructivist |
repository | https://github.com/polako-rs/constructivism |
max_upload_size | |
id | 994295 |
size | 105,320 |
constructivist
is the way to deliver constructivism
into your crate.
At some point you will realise that construtivism
is fucken awesome. And you want to use it in your crate. Let's call this crate polako
, just for example. And it also could happen that your crate is about to work with another crate (or framework, or engine), let's say it is about to work with bevy
(for example of course). You will meet one irresistible problem in this case: you can't implement a foreign trait for a foreign type. You can't implement constructivism::Construct
for bevy::Sprite
from your thouthend-times-amazing polako
crate.
This is how you become a constructivist
.
constructivis
t
allows you to inline the constructivis
m
into your crate. But. You are supposed to complete some steps.
I assume that you are using workspace and your crates live inside the crates
folder. There is also required naming convention with a single constraint: if your main crate is called awesomecrate
, then your constructivism crate have to be called awesomecrate_constructivism
. You can inspect how the real polako
inlines constructivism here: https://github.com/jkb0o/polako/tree/eml
constructivism_macro
. This is how you can create your polako_macro
crate:# in your favorite terminal:
cd crates
mkdir polako_macro
cd polako_macro
cargo init --lib
cargo add syn proc_macro2 quote constructivist
Cargo.toml
of this crate, and make this crate proc_macro
crate:# crates/polako_macro/Cargo.toml
[lib]
proc-macro = true
constructivism_macro
into your crate:// crates/polako_macro/src/lib.rs
implement_constructivism_macro!("polako");
constructivism_macro
in your crate.constructivism
in your crate:# we are in constructivism_macro dir for now, go back to crates
cd ../
mkdir polako_constructivism
cargo init --lib
cargo add --path ../polako_macro
# you most probably want to have your third-parti crate as dependency
cargo add bevy
// crates/polako_constructivism/src/lib.rs
pub use polako_macro::*;
// 32 is the maximum params limit, see (TODO: link the explanation)
implement_constructivism!(32);
bevy
in our example. Add the bridge mod to your crate:// crates/polako_constructivism/src/lib.rs
pub use polako_macro::*;
implement_constructivism!(32);
// add bridge mod:
mod bridge
// crates/polako_constructivism/src/bridge.rs
use bevy::prelude::*;
use polaco_macro::*;
derive_construct! {
NodeBundle -> Nothing () {
NodeBundle::default()
}
}
polako
. So, you HAVE to add constructivism
mod to your root crate to make it all work everywhere:// src/lib.rs
pub mod constructivism {
// this is required:
pub use polako_constructivism::*;
pub use polako_macro::*;
// this is optional (but nice):
pub mod prelude {
pub use polako_constructivism::prelude::*;
pub use polako_macro::*;
}
}
cargo-bootstrap-constructivism
(ask me how), provide astonished PR, and make this crate even better.The constructivist
is dual-licensed under either:
This means you can select the license you prefer! This dual-licensing approach is the de-facto standard in the Rust ecosystem and there are very good reasons to include both.