Skip to content

Add StableVec::extend method #349

@ranile

Description

@ranile

Currently the only way to extend a StableVec with another vector or slice is repeatedly calling push:

let stable_vec = StableVec::<u8, _>::init(mem).expect("Memory was not for stable vec");

let bytes = bincode::encode_to_vec(value, BINCODE_CONFIG).expect("Failed to serialize value");
for byte in bytes {
    stable_vec.push(&byte).expect("StableVec push failed");
}

The above code is very memory inefficient as it requires running the entire push code for every element (including growing memory!).

A similar method already exists for the std Vec: Vec::extend

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions