RSSAmplifier

openmymind.net · Feb 13, 2025

Switching on Strings in Zig

0
Sign in to vote or save

This site does not allow itself to be embedded. You can still read it on the original site — the toolbar below keeps your place in the directory.

Newcomers to Zig will quickly learn that you can't switch on a string (i.e. []const u8 ). The following code gives us the unambiguous error message cannot switch on strings : switch (color) { "red" => {}, "blue" => {}, "green" => {}, "pink" => {}, else => {}, } I've seen two explanations for why this isn't supported. The first is that there's ambiguity around string identity. Are two strings only…

Read on openmymind.net

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.