Skip to content

Feature: add Cow type #582

@ForsakenHarmony

Description

@ForsakenHarmony

It might be nice to have a Cow type in heapless.

pub enum Cow<'a, B, const N>
where
    B: ToOwned,
{
    Borrowed(&'a B),
    Owned(<B as ToOwned>::Owned<N>),
}

Example

let string = heapless::Cow<'static, str, 8>;
let vec = heapless::Cow<'a, [u8], 16>;

But I'm not sure if this is actually a good idea because you have to allocate the entire Owned object anyway.

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