Skip to content

Add ability to try to get an input and remove an input #6

Description

@jfecher

Currently, the only way to retrieve an input in inc-complete is to get the result of its computation:

fn main() {
    let mut db = Db::<MyStorage>::default();
    db.update_input(MyInput(3), 6);
    let input = MyInput(3).get(db);
    assert_eq!(input, 6);
}

However, this will panic if the input was never set:

#[test]
#[should_panic]
fn no_such_input() {
    let mut db = Db::<MyStorage>::default();
    let _ = MyInput(3).get(db);
}

It would be convenient if there was a way to query whether an input exists:

#[test]
fn no_such_input2() {
    let mut db = Db::<MyStorage>::default();
    let input = MyInput(3).try_get(db);
    assert_eq!(input, None);
}

Additionally, there is no way to remove existing inputs currently. This can lead to unnecessary bloat over time, particularly when reading from pre-existing serialized dbs. A way to remove inputs would be helpful:

#[test]
fn remove_input() {
    let mut db = Db::<MyStorage>::default();
    let input = MyInput(3);
   
    assert_eq!(input.try_get(db), None);
    input.set(db, 6);
    assert_eq!(input.try_get(db), Some(6));
    input.remove(db);
    assert_eq!(input.try_get(db), None);
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions