Skip to content

Consider "multi-effect" side effect to avoid needing tuples of effects #50

@GregoryConrad

Description

@GregoryConrad

I still think I want to keep the default register api as-is, but I think a side effect (in rearch-effects) like the following would be a nice touch:

let register = register(effects::multi::<16>()); // 16 is const generic for size of backing array
let (count, set_count) = register(effects::state::<Cloned<_>>(0));
let mut num_builds = register(effects::value::<MutRef<_>>(0));
*num_builds += 1;

Note that in the above example, the backing array size could be 2. 16 is just chosen as a sane default.

This should be possible with 100% safe rust via split_first_mut:

curr_slice = &mut backing_array;
register:
  let (curr_element, rest_slice) = self.curr_slice.split_first_mut().unwrap_or(|| panic!(“you need to increase length passed into multi!”));
  *self.curr_slice = rest_slice;
  return curr_element.some_cast_and_transform();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions