Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More flexible alternative to BufferContainer #85

Closed
DavJCosby opened this issue Nov 11, 2024 · 1 comment · Fixed by #92
Closed

More flexible alternative to BufferContainer #85

DavJCosby opened this issue Nov 11, 2024 · 1 comment · Fixed by #92
Assignees
Labels
design Discussing larger design and architecture ideas e/api Improving a method in the API, or adding a new one e/ergonomics Reducing friction for the end-user experience needs_thought Concepts that need to be explored more before they're ready to be worked on
Milestone

Comments

@DavJCosby
Copy link
Owner

DavJCosby commented Nov 11, 2024

This hit me in the shower today.

What if instead of this:

#[startup_commands]
fn startup(buffers: &mut BufferContainer) -> SledResult {
    let colors: &mut Vec<Rgb>  = buffers.create_buffer::<Rgb>("colors");
    colors.extend([
        Rgb::new(1.0, 0.0, 0.0),
        Rgb::new(0.0, 0.0, 1.0),
        Rgb::new(0.0, 1.0, 0.0),
    ]);
    Ok(())
}

we had something like this?

#[startup_commands]
fn startup(data: &mut DriverData) -> SledResult {
    data.set::<Vec<Rgb>>("colors", vec![
        Rgb::new(1.0, 0.0, 0.0),
        Rgb::new(0.0, 0.0, 1.0),
        Rgb::new(0.0, 1.0, 0.0),
    ]);
    //-- snip --
    Ok(())
}

(most type annotations are unnecessary and are only included for clarity)

Why?

Users don't always need to store a whole bunch of values at once. And sometimes when they do, they know how many values they'd like to store and would prefer to use a fixed-size array. This design lets you choose exactly how you'd like to store your data.

Filters would probably get dissolved by this too.
Instead of doing:

#[startup_commands]
fn startup(sled: &mut Sled, filters: &mut Filters) -> SledResult {
    let area: Filter = sled.within_dist_from(5.0, Vec2::new(-0.25, 1.5));
    filters.set("area_of_effect", area);
    //-- snip --
    Ok(())
}

You would do:

#[startup_commands]
fn startup(sled: &mut Sled, data: &mut DriverData) -> SledResult {
    let area: Filter = sled.within_dist_from(5.0, Vec2::new(-0.25, 1.5));
    data.set("area_of_effect", area);
    //-- snip --
    Ok(())
}

Methods

data.store::<T>(key: &str, value: T) -> &mut T;
data.set::<T>(key: &str, value: T);
data.get::<T>(key: &str) -> SledResult<&T>;
data.get_mut::<T>(key: &str) -> SledResult<&mut T>;
data.exists::<T>(key: &str) -> bool;
data.empty_at(key: &str) -> bool;
@DavJCosby DavJCosby added e/api Improving a method in the API, or adding a new one design Discussing larger design and architecture ideas e/ergonomics Reducing friction for the end-user experience needs_thought Concepts that need to be explored more before they're ready to be worked on labels Nov 11, 2024
@DavJCosby DavJCosby added this to the 0.2.0 milestone Nov 11, 2024
@github-project-automation github-project-automation bot moved this to Backlog in 0.2 Roadmap Nov 11, 2024
@DavJCosby
Copy link
Owner Author

Beginning work on the BufferContainerOverhaul branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Discussing larger design and architecture ideas e/api Improving a method in the API, or adding a new one e/ergonomics Reducing friction for the end-user experience needs_thought Concepts that need to be explored more before they're ready to be worked on
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant