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.

Update wording of IterableStorageMap docs #10358

@xlc

Description

@xlc

/// Enumerate all elements in the map in lexicographical order of the encoded key. If you
/// alter the map while doing this, you'll get undefined results.

The undefined results wording is very uncomfortable to me as someone with C++ background. There are no undefined behaviour here. There maybe unexpected result depends on the how the map is altered. Deleting item is perfectly fine, update value is also ok. Only add item means it may or may not be iterated later depends on the hash value of the key. Can we update the docs to make it more clear?

pub trait IterableStorageMap<K: FullEncode, V: FullCodec>: StorageMap<K, V> {
/// The type that iterates over all `(key, value)`.
type Iterator: Iterator<Item = (K, V)>;
/// The type that itereates over all `key`s.
type KeyIterator: Iterator<Item = K>;
/// Enumerate all elements in the map in lexicographical order of the encoded key. If you
/// alter the map while doing this, you'll get undefined results.
fn iter() -> Self::Iterator;
/// Enumerate all elements in the map after a specified `starting_raw_key` in lexicographical
/// order of the encoded key. If you alter the map while doing this, you'll get undefined
/// results.
fn iter_from(starting_raw_key: Vec<u8>) -> Self::Iterator;
/// Enumerate all keys in the map in lexicographical order of the encoded key, skipping over
/// the elements. If you alter the map while doing this, you'll get undefined results.
fn iter_keys() -> Self::KeyIterator;
/// Enumerate all keys in the map after a specified `starting_raw_key` in lexicographical order
/// of the encoded key. If you alter the map while doing this, you'll get undefined results.
fn iter_keys_from(starting_raw_key: Vec<u8>) -> Self::KeyIterator;
/// Remove all elements from the map and iterate through them in lexicographical order of the
/// encoded key. If you add elements to the map while doing this, you'll get undefined results.
fn drain() -> Self::Iterator;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions