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

mutate API for storage entries #667

Closed
gavofyork opened this issue Sep 5, 2018 · 0 comments
Closed

mutate API for storage entries #667

gavofyork opened this issue Sep 5, 2018 · 0 comments
Labels
I7-refactor Code needs refactoring. Z1-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder
Milestone

Comments

@gavofyork
Copy link
Member

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/).

@gavofyork gavofyork added this to the As-and-when milestone Sep 5, 2018
@gavofyork gavofyork added I7-refactor Code needs refactoring. Z1-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder labels Sep 5, 2018
@guanqun guanqun mentioned this issue Sep 9, 2018
helin6 pushed a commit to boolnetwork/substrate that referenced this issue Jul 25, 2023
* refactor CLI commands for easier expansion

* add license headers

* cargo fmt
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
I7-refactor Code needs refactoring. Z1-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder
Projects
None yet
Development

No branches or pull requests

1 participant