mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Contracts on generic modules would evaluate too late, sometimes not catching the error until it already occurred elsewhere. Add file::save.
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
<*
|
||||
@require values::@is_int(SIZE) &&& SIZE > 0 "The size must be positive integer"
|
||||
*>
|
||||
module std::collections::ringbuffer(<Type, SIZE>);
|
||||
|
||||
struct RingBuffer
|
||||
|
||||
@@ -182,6 +182,17 @@ fn char[]! load_temp(String filename)
|
||||
return load_new(filename, allocator::temp());
|
||||
}
|
||||
|
||||
fn void! save(String filename, char[] data)
|
||||
{
|
||||
File file = open(filename, "wb")!;
|
||||
defer (void)file.close();
|
||||
while (data.len)
|
||||
{
|
||||
usz written = file.write(data)!;
|
||||
data = data[written..];
|
||||
}
|
||||
}
|
||||
|
||||
<*
|
||||
@require self.file `File must be initialized`
|
||||
*>
|
||||
|
||||
Reference in New Issue
Block a user