Skip to content

Syntax improvement for ResultQuery usage #259

@KiChjang

Description

@KiChjang

paritytech/substrate#11257 introduces ResultQuery, which contain syntax that is in fact non-standard Rust when trying to use it as the QueryKind type parameter for a storage map. Example:

pub type Map3<T> = StorageMap<
	_,
	Blake2_128Concat,
	u32,
	u64,
	ResultQuery<Error<T>::NonExistentStorageValue>, // <---- This is non-standard Rust syntax
>;

The reason here is because Error<T>::NonExistentStorageValue is not a type, but rather a value, as enum variants are currently not properly recognized as their own proper types in Rust.

In addition, such a syntax does not cater to enum variants that accept fields, so implementors are forced to also use the OnEmpty parameter to specify what the default Result value should be when the corresponding value doesn't exist under the storage key specified.

We'd like to try and stick with standard Rust syntax as much as possible, and as a stretch goal, also allow for the flexibility of specifying the default query value without the usage of OnEmpty.

Metadata

Metadata

Assignees

No one assigned

    Labels

    D1-mediumCan be fixed by a coder with good Rust knowledge but little knowledge of the codebase.I3-annoyanceThe node behaves within expectations, however this “expected behaviour” itself is at issue.I5-enhancementAn additional feature request.T1-FRAMEThis PR/Issue is related to core FRAME, the framework.

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions