Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

mutate API for storage entries #667

@gavofyork

Description

@gavofyork

Currently storage items have put and get. This can be fairly cumbersome when all you want to do is a minor mutation like push an item to the end of a Vec or increment by 1.

We should introduce the mutate API which basically works as:

struct X {
	fn get() -> Option<Value> { ... }
	fn put(v: Value) { ... }
	fn kill() { ... }
	fn mutate<F: FnOnce(mut v: Option<Value>)>(key: Key, f: F) {
		let mut a = Self::get(); 
		f(a);
		match a {
			None => Self::kill(),
			Some(v) => Self::put(v),
		}
	}
}

It should work correctly with maps (an extra key parameter and s/put,kill/insert,remove/) and with default/required variations (s/Option/Value/).

Metadata

Metadata

Assignees

No one assigned

    Labels

    I7-refactorCode needs refactoring.Z1-easyCan be fixed primarily by duplicating and adapting code by an intermediate coder

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions