Coder Social home page Coder Social logo

Feature list about hax HOT 4 CLOSED

hax-rs avatar hax-rs commented on May 30, 2024
Feature list

from hax.

Comments (4)

not-matthias avatar not-matthias commented on May 30, 2024

Experimented a little bit and i think we could use the inventory crate for feature registration.

image

it has a few downsides though:

  1. 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.
  2. 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.

7ap avatar 7ap commented on May 30, 2024

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.

not-matthias avatar not-matthias commented on May 30, 2024

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.

not-matthias avatar not-matthias commented on May 30, 2024

Implemented the first draft. See:

@7ap Feedback is welcome.

from hax.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.