Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: BufMap.set() returns the copied value #8533

Open
akvadrako opened this issue Apr 14, 2021 · 0 comments
Open

Proposal: BufMap.set() returns the copied value #8533

akvadrako opened this issue Apr 14, 2021 · 0 comments
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@akvadrako
Copy link
Contributor

akvadrako commented Apr 14, 2021

Currently BufMap.set(key, value) copies the value and stores it, but it only returns errors. BufMap is probably being used because value won't live long and a copy is desired for further processing. So now you might need to do this:

fn saveValue(key: []u8, value: []const u8) ![]const u8 {
    try map.set(key, value);
    if (map.get(key)) |v| {
      storePointer(v);
      return v;
    }
    unreachable;
}

If set would return the copy one could do this instead:

fn saveValue(key: []u8, value: []const u8) ![]const u8 {
    const v = try map.set(key, value);
    storePointer(v);
    return v;
}

BTW I've just started using Zig last week so I could certainly be missing something in how this is supposed to be used.

@andrewrk andrewrk added proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. standard library This issue involves writing Zig code for the standard library. labels Apr 15, 2021
@andrewrk andrewrk added this to the 1.0.0 milestone Apr 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

No branches or pull requests

2 participants