ref: afee16c01916327f6cf229bb911e7166041063a2
parent: 1ac88fcd0d2f000dac2119cf52e3bd7c60200b96
author: Ori Bernstein <ori@eigenstate.org>
date: Sun May 6 02:58:44 EDT 2018
Make std.writeall api slightly nicer.
--- a/lib/std/fmt.myr
+++ b/lib/std/fmt.myr
@@ -111,16 +111,17 @@
}
const fputv = {fd, fmt, ap
- var sb, s
+ var sb, s, nw
sb = mksb()
sbfmtv(sb, fmt, ap)
s = sbfin(sb)
match writeall(fd, s)
- | (n, _):
- slfree(s)
- -> n
+ | `std.Ok n: nw += n
+ | `std.Err (n, _): nw += n
;;
+ slfree(s)
+ -> nw
}
const fmt = {fmt, args
--- a/lib/std/writeall.myr
+++ b/lib/std/writeall.myr
@@ -5,7 +5,7 @@
use "types"
pkg std =
- const writeall : (fd : fd, src : byte[:] -> (size, option(errno)))
+ const writeall : (fd : fd, src : byte[:] -> std.result(size, (size, errno)))
;;
const writeall = {fd, src
@@ -15,8 +15,8 @@
while src.len != 0
match std.write(fd, src)
| `Ok n: src = src[n:]
- | `Err e: -> (sz - src.len, `Some e)
+ | `Err e: -> `std.Err (sz, e)
;;
;;
- -> (sz, `None)
+ -> `std.Ok sz
}