diff options
| author | gingerBill <bill@gingerbill.org> | 2021-09-29 13:24:42 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-09-29 13:24:42 +0100 |
| commit | b2164b5da604e62aa24eeb9c77fc72128afe7f89 (patch) | |
| tree | ada5161e3eb3cb792c176b8e33710836e8c1ca1c | |
| parent | 057310472e453a4cda7c93daa15115ca99ee9b90 (diff) | |
Make the io/conv.odin utilities be `#optional_ok`
| -rw-r--r-- | core/fmt/fmt.odin | 10 | ||||
| -rw-r--r-- | core/io/conv.odin | 44 | ||||
| -rw-r--r-- | core/strings/builder.odin | 3 | ||||
| -rw-r--r-- | core/testing/runner.odin | 2 |
4 files changed, 29 insertions, 30 deletions
diff --git a/core/fmt/fmt.odin b/core/fmt/fmt.odin index 04fb08425..f0e6147bf 100644 --- a/core/fmt/fmt.odin +++ b/core/fmt/fmt.odin @@ -63,24 +63,24 @@ register_user_formatter :: proc(id: typeid, formatter: User_Formatter) -> Regist fprint :: proc(fd: os.Handle, args: ..any, sep := " ") -> int { - w, _ := io.to_writer(os.stream_from_handle(fd)) + w := io.to_writer(os.stream_from_handle(fd)) return wprint(w=w, args=args, sep=sep) } fprintln :: proc(fd: os.Handle, args: ..any, sep := " ") -> int { - w, _ := io.to_writer(os.stream_from_handle(fd)) + w := io.to_writer(os.stream_from_handle(fd)) return wprintln(w=w, args=args, sep=sep) } fprintf :: proc(fd: os.Handle, fmt: string, args: ..any) -> int { - w, _ := io.to_writer(os.stream_from_handle(fd)) + w := io.to_writer(os.stream_from_handle(fd)) return wprintf(w, fmt, ..args) } fprint_type :: proc(fd: os.Handle, info: ^runtime.Type_Info) -> int { - w, _ := io.to_writer(os.stream_from_handle(fd)) + w := io.to_writer(os.stream_from_handle(fd)) return wprint_type(w, info) } fprint_typeid :: proc(fd: os.Handle, id: typeid) -> int { - w, _ := io.to_writer(os.stream_from_handle(fd)) + w := io.to_writer(os.stream_from_handle(fd)) return wprint_typeid(w, id) } diff --git a/core/io/conv.odin b/core/io/conv.odin index af20866f2..baaf5a864 100644 --- a/core/io/conv.odin +++ b/core/io/conv.odin @@ -1,13 +1,13 @@ package io -to_reader :: proc(s: Stream) -> (r: Reader, ok: bool = true) { +to_reader :: proc(s: Stream) -> (r: Reader, ok: bool = true) #optional_ok { r.stream = s if s.stream_vtable == nil || s.impl_read == nil { ok = false } return } -to_writer :: proc(s: Stream) -> (w: Writer, ok: bool = true) { +to_writer :: proc(s: Stream) -> (w: Writer, ok: bool = true) #optional_ok { w.stream = s if s.stream_vtable == nil || s.impl_write == nil { ok = false @@ -15,21 +15,21 @@ to_writer :: proc(s: Stream) -> (w: Writer, ok: bool = true) { return } -to_closer :: proc(s: Stream) -> (c: Closer, ok: bool = true) { +to_closer :: proc(s: Stream) -> (c: Closer, ok: bool = true) #optional_ok { c.stream = s if s.stream_vtable == nil || s.impl_close == nil { ok = false } return } -to_flusher :: proc(s: Stream) -> (f: Flusher, ok: bool = true) { +to_flusher :: proc(s: Stream) -> (f: Flusher, ok: bool = true) #optional_ok { f.stream = s if s.stream_vtable == nil || s.impl_flush == nil { ok = false } return } -to_seeker :: proc(s: Stream) -> (seeker: Seeker, ok: bool = true) { +to_seeker :: proc(s: Stream) -> (seeker: Seeker, ok: bool = true) #optional_ok { seeker.stream = s if s.stream_vtable == nil || s.impl_seek == nil { ok = false @@ -37,42 +37,42 @@ to_seeker :: proc(s: Stream) -> (seeker: Seeker, ok: bool = true) { return } -to_read_writer :: proc(s: Stream) -> (r: Read_Writer, ok: bool = true) { +to_read_writer :: proc(s: Stream) -> (r: Read_Writer, ok: bool = true) #optional_ok { r.stream = s if s.stream_vtable == nil || s.impl_read == nil || s.impl_write == nil { ok = false } return } -to_read_closer :: proc(s: Stream) -> (r: Read_Closer, ok: bool = true) { +to_read_closer :: proc(s: Stream) -> (r: Read_Closer, ok: bool = true) #optional_ok { r.stream = s if s.stream_vtable == nil || s.impl_read == nil || s.impl_close == nil { ok = false } return } -to_read_write_closer :: proc(s: Stream) -> (r: Read_Write_Closer, ok: bool = true) { +to_read_write_closer :: proc(s: Stream) -> (r: Read_Write_Closer, ok: bool = true) #optional_ok { r.stream = s if s.stream_vtable == nil || s.impl_read == nil || s.impl_write == nil || s.impl_close == nil { ok = false } return } -to_read_write_seeker :: proc(s: Stream) -> (r: Read_Write_Seeker, ok: bool = true) { +to_read_write_seeker :: proc(s: Stream) -> (r: Read_Write_Seeker, ok: bool = true) #optional_ok { r.stream = s if s.stream_vtable == nil || s.impl_read == nil || s.impl_write == nil || s.impl_seek == nil { ok = false } return } -to_write_flusher :: proc(s: Stream) -> (w: Write_Flusher, ok: bool = true) { +to_write_flusher :: proc(s: Stream) -> (w: Write_Flusher, ok: bool = true) #optional_ok { w.stream = s if s.stream_vtable == nil || s.impl_write == nil || s.impl_flush == nil { ok = false } return } -to_write_flush_closer :: proc(s: Stream) -> (w: Write_Flush_Closer, ok: bool = true) { +to_write_flush_closer :: proc(s: Stream) -> (w: Write_Flush_Closer, ok: bool = true) #optional_ok { w.stream = s if s.stream_vtable == nil || s.impl_write == nil || s.impl_flush == nil || s.impl_close == nil { ok = false @@ -80,42 +80,42 @@ to_write_flush_closer :: proc(s: Stream) -> (w: Write_Flush_Closer, ok: bool = t return } -to_reader_at :: proc(s: Stream) -> (r: Reader_At, ok: bool = true) { +to_reader_at :: proc(s: Stream) -> (r: Reader_At, ok: bool = true) #optional_ok { r.stream = s if s.stream_vtable == nil || s.impl_read_at == nil { ok = false } return } -to_writer_at :: proc(s: Stream) -> (w: Writer_At, ok: bool = true) { +to_writer_at :: proc(s: Stream) -> (w: Writer_At, ok: bool = true) #optional_ok { w.stream = s if s.stream_vtable == nil || s.impl_write_at == nil { ok = false } return } -to_reader_from :: proc(s: Stream) -> (r: Reader_From, ok: bool = true) { +to_reader_from :: proc(s: Stream) -> (r: Reader_From, ok: bool = true) #optional_ok { r.stream = s if s.stream_vtable == nil || s.impl_read_from == nil { ok = false } return } -to_writer_to :: proc(s: Stream) -> (w: Writer_To, ok: bool = true) { +to_writer_to :: proc(s: Stream) -> (w: Writer_To, ok: bool = true) #optional_ok { w.stream = s if s.stream_vtable == nil || s.impl_write_to == nil { ok = false } return } -to_write_closer :: proc(s: Stream) -> (w: Write_Closer, ok: bool = true) { +to_write_closer :: proc(s: Stream) -> (w: Write_Closer, ok: bool = true) #optional_ok { w.stream = s if s.stream_vtable == nil || s.impl_write == nil || s.impl_close == nil { ok = false } return } -to_write_seeker :: proc(s: Stream) -> (w: Write_Seeker, ok: bool = true) { +to_write_seeker :: proc(s: Stream) -> (w: Write_Seeker, ok: bool = true) #optional_ok { w.stream = s if s.stream_vtable == nil || s.impl_write == nil || s.impl_seek == nil { ok = false @@ -124,7 +124,7 @@ to_write_seeker :: proc(s: Stream) -> (w: Write_Seeker, ok: bool = true) { } -to_byte_reader :: proc(s: Stream) -> (b: Byte_Reader, ok: bool = true) { +to_byte_reader :: proc(s: Stream) -> (b: Byte_Reader, ok: bool = true) #optional_ok { b.stream = s if s.stream_vtable == nil || s.impl_read_byte == nil { ok = false @@ -134,7 +134,7 @@ to_byte_reader :: proc(s: Stream) -> (b: Byte_Reader, ok: bool = true) { } return } -to_byte_scanner :: proc(s: Stream) -> (b: Byte_Scanner, ok: bool = true) { +to_byte_scanner :: proc(s: Stream) -> (b: Byte_Scanner, ok: bool = true) #optional_ok { b.stream = s if s.stream_vtable != nil { if s.impl_unread_byte == nil { @@ -151,7 +151,7 @@ to_byte_scanner :: proc(s: Stream) -> (b: Byte_Scanner, ok: bool = true) { } return } -to_byte_writer :: proc(s: Stream) -> (b: Byte_Writer, ok: bool = true) { +to_byte_writer :: proc(s: Stream) -> (b: Byte_Writer, ok: bool = true) #optional_ok { b.stream = s if s.stream_vtable == nil || s.impl_write_byte == nil { ok = false @@ -162,7 +162,7 @@ to_byte_writer :: proc(s: Stream) -> (b: Byte_Writer, ok: bool = true) { return } -to_rune_reader :: proc(s: Stream) -> (r: Rune_Reader, ok: bool = true) { +to_rune_reader :: proc(s: Stream) -> (r: Rune_Reader, ok: bool = true) #optional_ok { r.stream = s if s.stream_vtable == nil || s.impl_read_rune == nil { ok = false @@ -173,7 +173,7 @@ to_rune_reader :: proc(s: Stream) -> (r: Rune_Reader, ok: bool = true) { return } -to_rune_scanner :: proc(s: Stream) -> (r: Rune_Scanner, ok: bool = true) { +to_rune_scanner :: proc(s: Stream) -> (r: Rune_Scanner, ok: bool = true) #optional_ok { r.stream = s if s.stream_vtable != nil { if s.impl_unread_rune == nil { diff --git a/core/strings/builder.odin b/core/strings/builder.odin index 3396971e3..b4b1e43b2 100644 --- a/core/strings/builder.odin +++ b/core/strings/builder.odin @@ -80,8 +80,7 @@ to_stream :: proc(b: ^Builder) -> io.Stream { return io.Stream{stream_vtable=_builder_stream_vtable, stream_data=b} } to_writer :: proc(b: ^Builder) -> io.Writer { - w, _ := io.to_writer(to_stream(b)) - return w + return io.to_writer(to_stream(b)) } diff --git a/core/testing/runner.odin b/core/testing/runner.odin index 359039243..0039f1939 100644 --- a/core/testing/runner.odin +++ b/core/testing/runner.odin @@ -18,7 +18,7 @@ end_t :: proc(t: ^T) { runner :: proc(internal_tests: []Internal_Test) -> bool { stream := os.stream_from_handle(os.stdout) - w, _ := io.to_writer(stream) + w := io.to_writer(stream) t := &T{} t.w = w |