Zig 0.17.0-dev (Split by item)
This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig library itself.
Zig › std/ › Io.zig › Limit
Limit
Io.Limit
pub const Limit = enum (usize )
File
Code
pub const Limit = enum (usize ) {
nothing = 0 ,
unlimited = math .maxInt (usize ),
_ ,
pub fn limited (n : usize ) Limit {
return @fromBackingInt (@intCast (n ));
}
pub fn limited64 (n : u64 ) Limit {
return @fromBackingInt (@intCast (@min (n , math .maxInt (usize ))));
}
pub fn countVec (data : []const []const u8 ) Limit {
var total : usize = 0 ;
for (data ) |d | total += d .len ;
return .limited (total );
}
pub fn min (a : Limit , b : Limit ) Limit {
return @fromBackingInt (@intCast (@min (@backingInt (a ), @backingInt (b ))));
}
pub fn max (a : Limit , b : Limit ) Limit {
if (a == .unlimited or b == .unlimited ) {
return .unlimited ;
}
return @fromBackingInt (@intCast (@max (@backingInt (a ), @backingInt (b ))));
}
pub fn minInt (l : Limit , n : usize ) usize {
return @min (n , @backingInt (l ));
}
pub fn minInt64 (l : Limit , n : u64 ) usize {
return @min (n , @backingInt (l ));
}
pub fn slice (l : Limit , s : []u8 ) []u8 {
return s [0 ..l .minInt (s .len )];
}
pub fn sliceConst (l : Limit , s : []const u8 ) []const u8 {
return s [0 ..l .minInt (s .len )];
}
pub fn toInt (l : Limit ) ?usize {
return switch (l ) {
else => @backingInt (l ),
.unlimited => null ,
};
}
pub fn toInt64 (l : Limit ) ?u64 {
return switch (l ) {
else => @backingInt (l ),
.unlimited => null ,
};
}
pub fn slice1 (l : Limit , non_empty_buffer : []u8 ) []u8 {
assert (non_empty_buffer .len >= 1 );
return non_empty_buffer [0 ..@min (@backingInt (l ) +| 1 , non_empty_buffer .len )];
}
pub fn nonzero (l : Limit ) bool {
return l != .nothing ;
}
pub fn subtract (l : Limit , amount : usize ) ?Limit {
if (l == .unlimited ) return .unlimited ;
if (amount > @backingInt (l )) return null ;
return @fromBackingInt (@intCast (@backingInt (l ) - amount ));
}
}