enum SpecialProngs [src]
Fields
none = 0b000
@"else" = 0b001Simple else prong.
else => {},
under = 0b010Simple _ prong.
_ => {},
under_and_else = 0b011Both an else and a _ prong.
else => {},
_ => {},
under_one_item = 0b100_ prong with 1 additional item.
a, _ => {},
under_one_item_and_else = 0b101Both an else and a _ prong with 1 additional item.
else => {},
a, _ => {},
under_many_items = 0b110_ prong with >1 additional items.
a, _, b => {},
under_many_items_and_else = 0b111Both an else and a _ prong with >1 additional items.
else => {},
a, _, b => {},
Members
- AdditionalItems (enum)
- hasAdditionalItems (Function)
- hasElse (Function)
- hasManyAdditionalItems (Function)
- hasOneAdditionalItem (Function)
- hasUnder (Function)
- init (Function)
Source
pub const SpecialProngs = enum(u3) {
none = 0b000,
/// Simple `else` prong.
/// `else => {},`
@"else" = 0b001,
/// Simple `_` prong.
/// `_ => {},`
under = 0b010,
/// Both an `else` and a `_` prong.
/// `else => {},`
/// `_ => {},`
under_and_else = 0b011,
/// `_` prong with 1 additional item.
/// `a, _ => {},`
under_one_item = 0b100,
/// Both an `else` and a `_` prong with 1 additional item.
/// `else => {},`
/// `a, _ => {},`
under_one_item_and_else = 0b101,
/// `_` prong with >1 additional items.
/// `a, _, b => {},`
under_many_items = 0b110,
/// Both an `else` and a `_` prong with >1 additional items.
/// `else => {},`
/// `a, _, b => {},`
under_many_items_and_else = 0b111,
pub const AdditionalItems = enum(u3) {
none = @intFromEnum(SpecialProngs.under),
one = @intFromEnum(SpecialProngs.under_one_item),
many = @intFromEnum(SpecialProngs.under_many_items),
};
pub fn init(has_else: bool, has_under: bool, additional_items: AdditionalItems) SpecialProngs {
const else_bit: u3 = @intFromBool(has_else);
const under_bits: u3 = if (has_under)
@intFromEnum(additional_items)
else
@intFromEnum(SpecialProngs.none);
return @enumFromInt(else_bit | under_bits);
}
pub fn hasElse(special_prongs: SpecialProngs) bool {
return (@intFromEnum(special_prongs) & 0b001) != 0;
}
pub fn hasUnder(special_prongs: SpecialProngs) bool {
return (@intFromEnum(special_prongs) & 0b110) != 0;
}
pub fn hasAdditionalItems(special_prongs: SpecialProngs) bool {
return (@intFromEnum(special_prongs) & 0b100) != 0;
}
pub fn hasOneAdditionalItem(special_prongs: SpecialProngs) bool {
return (@intFromEnum(special_prongs) & 0b110) == @intFromEnum(SpecialProngs.under_one_item);
}
pub fn hasManyAdditionalItems(special_prongs: SpecialProngs) bool {
return (@intFromEnum(special_prongs) & 0b110) == @intFromEnum(SpecialProngs.under_many_items);
}
}