Comments (4)
Experimented a little bit and i think we could use the inventory
crate for feature registration.
it has a few downsides though:
- these are registered by the loader, so if you are manual mapping, you need to make sure that these are handled correctly. We could use linkme (https://docs.rs/linkme/0.3.6/linkme/) then, since it only requires linker features.
- you need to create the struct at compile-time. linkme could be used to expose an init function, which returns the struct.
@7ap what do you think?
from hax.
I think this is a great solution! I'll need to take a look at inventory myself but from your screenshots it shows like it does what it needs to do.
from hax.
Implemented both versions and I think it's easier to go for linkme
.
inventory
We can't just create the object, we need to pass the function so that we can create it at compile time.
use crate::{Feature, FeatureTrait};
pub struct Esp {
pub enabled: bool,
}
impl FeatureTrait for Esp {
fn new() -> Box<dyn FeatureTrait> {
Box::new(Self { enabled: false })
}
}
inventory::submit! {
Feature::new("ESP", Esp::new)
}
linkme
Here we also have the option to link one function, but it's much less verbose and doesn't require life-before-main. We can hide the functionality of linkme
so that they never even have to specify the initialization function.
use linkme::distributed_slice;
use crate::Feature;
pub struct Esp {
pub enabled: bool,
}
impl Feature for Esp {
fn new() -> Box<Self> {
Box::new(Self { enabled: false })
}
}
#[distributed_slice(crate::FEATURES)]
fn init_esp() -> Box<dyn Feature> {
println!("Init esp");
Esp::new()
}
from hax.
Implemented the first draft. See:
- https://github.com/hax-rs/hax/blob/feature/hax/examples/feature.rs
- https://github.com/hax-rs/hax/blob/feature/hax/examples/external.rs
@7ap Feedback is welcome.
from hax.
Related Issues (5)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hax.