#struct field change via doesn't works

1 messages · Page 1 of 1 (latest)

full nexus
#

I'm making my own implementation of linked list, the problem is when i try to set value to node via set method it doesn't changes

Here is my main.zig

const std = @import("std");
const structs = @import("structs.zig");

const allocator = std.heap.page_allocator;

pub fn main() !void {
    var list = structs.SinglyLinkedList(i32).init(allocator);
    try list.add(10);
    try list.add(10);
    try list.add(10);
    try list.add(50);
    try list.add(500);

    try list.set(1, 999);

    var list_iter = list.iterator();
    while (list_iter.next()) |item| {
        std.debug.print("item -> {}\n", .{item});
    }
}

What am i doing wrong?

#

struct field change via doesn't works

quiet topaz
#

As a general rule, if you're reaching for @constCast, you're doing something wrong

#

Instead of returning item.value from next, return &item.value (and hence change the return type to ?*T)