#can't assign a constant

1 messages · Page 1 of 1 (latest)

pastel pulsar
#

const Server = struct {
    const Self = @This();

    port: u16,
    server: *net.Server,
    allocator: mem.Allocator,
    addr: net.Address,
    public: bool,

    fn init_ip(public: bool, port: u16) net.Address {
        if (public) {
            return net.Address.initIp4(.{ 0, 0, 0, 0 }, port);
        } else {
            return net.Address.initIp4(.{ 127, 0, 0, 1 }, port);
        }
    }

    pub fn init(allocator: mem.Allocator, port: u16, public: ?bool) !*Server {
        var self = try allocator.create(Self);
        self.allocator = allocator;
        self.port = port;
        self.public = public orelse false;
        self.addr = init_ip(self.public, self.port);

        return self;
    }
    pub fn deinit(self: Self) void {
        self.allocator.destroy(self);
    }
    fn mainloop() void {
        std.debug.print("Server started\n", .{});
    }
    pub fn run(self: Self) !void {
        const listen_config = net.Address.ListenOptions{ .reuse_address = true, .reuse_port = true };
        const server = try self.addr.listen(listen_config);
        self.server = &server;
        mainloop();
    }
};
#

Idk why this is happening

signal hinge
#

fn run(self: *Self)