Browse Source

Make the io/conv.odin utilities be `#optional_ok`

gingerBill 3 years ago
parent
commit
b2164b5da6
4 changed files with 29 additions and 30 deletions
  1. 5 5
      core/fmt/fmt.odin
  2. 22 22
      core/io/conv.odin
  3. 1 2
      core/strings/builder.odin
  4. 1 1
      core/testing/runner.odin

+ 5 - 5
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 {
 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)
 	return wprint(w=w, args=args, sep=sep)
 }
 }
 
 
 fprintln :: proc(fd: os.Handle, args: ..any, sep := " ") -> int {
 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)
 	return wprintln(w=w, args=args, sep=sep)
 }
 }
 fprintf :: proc(fd: os.Handle, fmt: string, args: ..any) -> int {
 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)
 	return wprintf(w, fmt, ..args)
 }
 }
 fprint_type :: proc(fd: os.Handle, info: ^runtime.Type_Info) -> int {
 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)
 	return wprint_type(w, info)
 }
 }
 fprint_typeid :: proc(fd: os.Handle, id: typeid) -> int {
 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)
 	return wprint_typeid(w, id)
 }
 }
 
 

+ 22 - 22
core/io/conv.odin

@@ -1,13 +1,13 @@
 package io
 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
 	r.stream = s
 	if s.stream_vtable == nil || s.impl_read == nil {
 	if s.stream_vtable == nil || s.impl_read == nil {
 		ok = false
 		ok = false
 	}
 	}
 	return
 	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
 	w.stream = s
 	if s.stream_vtable == nil || s.impl_write == nil {
 	if s.stream_vtable == nil || s.impl_write == nil {
 		ok = false
 		ok = false
@@ -15,21 +15,21 @@ to_writer :: proc(s: Stream) -> (w: Writer, ok: bool = true) {
 	return
 	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
 	c.stream = s
 	if s.stream_vtable == nil || s.impl_close == nil {
 	if s.stream_vtable == nil || s.impl_close == nil {
 		ok = false
 		ok = false
 	}
 	}
 	return
 	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
 	f.stream = s
 	if s.stream_vtable == nil || s.impl_flush == nil {
 	if s.stream_vtable == nil || s.impl_flush == nil {
 		ok = false
 		ok = false
 	}
 	}
 	return
 	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
 	seeker.stream = s
 	if s.stream_vtable == nil || s.impl_seek == nil {
 	if s.stream_vtable == nil || s.impl_seek == nil {
 		ok = false
 		ok = false
@@ -37,42 +37,42 @@ to_seeker :: proc(s: Stream) -> (seeker: Seeker, ok: bool = true) {
 	return
 	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
 	r.stream = s
 	if s.stream_vtable == nil || s.impl_read == nil || s.impl_write == nil {
 	if s.stream_vtable == nil || s.impl_read == nil || s.impl_write == nil {
 		ok = false
 		ok = false
 	}
 	}
 	return
 	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
 	r.stream = s
 	if s.stream_vtable == nil || s.impl_read == nil || s.impl_close == nil {
 	if s.stream_vtable == nil || s.impl_read == nil || s.impl_close == nil {
 		ok = false
 		ok = false
 	}
 	}
 	return
 	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
 	r.stream = s
 	if s.stream_vtable == nil || s.impl_read == nil || s.impl_write == nil || s.impl_close == nil {
 	if s.stream_vtable == nil || s.impl_read == nil || s.impl_write == nil || s.impl_close == nil {
 		ok = false
 		ok = false
 	}
 	}
 	return
 	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
 	r.stream = s
 	if s.stream_vtable == nil || s.impl_read == nil || s.impl_write == nil || s.impl_seek == nil {
 	if s.stream_vtable == nil || s.impl_read == nil || s.impl_write == nil || s.impl_seek == nil {
 		ok = false
 		ok = false
 	}
 	}
 	return
 	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
 	w.stream = s
 	if s.stream_vtable == nil || s.impl_write == nil || s.impl_flush == nil {
 	if s.stream_vtable == nil || s.impl_write == nil || s.impl_flush == nil {
 		ok = false
 		ok = false
 	}
 	}
 	return
 	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
 	w.stream = s
 	if s.stream_vtable == nil || s.impl_write == nil || s.impl_flush == nil || s.impl_close == nil {
 	if s.stream_vtable == nil || s.impl_write == nil || s.impl_flush == nil || s.impl_close == nil {
 		ok = false
 		ok = false
@@ -80,42 +80,42 @@ to_write_flush_closer :: proc(s: Stream) -> (w: Write_Flush_Closer, ok: bool = t
 	return
 	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
 	r.stream = s
 	if s.stream_vtable == nil || s.impl_read_at == nil {
 	if s.stream_vtable == nil || s.impl_read_at == nil {
 		ok = false
 		ok = false
 	}
 	}
 	return
 	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
 	w.stream = s
 	if s.stream_vtable == nil || s.impl_write_at == nil {
 	if s.stream_vtable == nil || s.impl_write_at == nil {
 		ok = false
 		ok = false
 	}
 	}
 	return
 	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
 	r.stream = s
 	if s.stream_vtable == nil || s.impl_read_from == nil {
 	if s.stream_vtable == nil || s.impl_read_from == nil {
 		ok = false
 		ok = false
 	}
 	}
 	return
 	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
 	w.stream = s
 	if s.stream_vtable == nil || s.impl_write_to == nil {
 	if s.stream_vtable == nil || s.impl_write_to == nil {
 		ok = false
 		ok = false
 	}
 	}
 	return
 	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
 	w.stream = s
 	if s.stream_vtable == nil || s.impl_write == nil || s.impl_close == nil {
 	if s.stream_vtable == nil || s.impl_write == nil || s.impl_close == nil {
 		ok = false
 		ok = false
 	}
 	}
 	return
 	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
 	w.stream = s
 	if s.stream_vtable == nil || s.impl_write == nil || s.impl_seek == nil {
 	if s.stream_vtable == nil || s.impl_write == nil || s.impl_seek == nil {
 		ok = false
 		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
 	b.stream = s
 	if s.stream_vtable == nil || s.impl_read_byte == nil {
 	if s.stream_vtable == nil || s.impl_read_byte == nil {
 		ok = false
 		ok = false
@@ -134,7 +134,7 @@ to_byte_reader :: proc(s: Stream) -> (b: Byte_Reader, ok: bool = true) {
 	}
 	}
 	return
 	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
 	b.stream = s
 	if s.stream_vtable != nil {
 	if s.stream_vtable != nil {
 		if s.impl_unread_byte == nil {
 		if s.impl_unread_byte == nil {
@@ -151,7 +151,7 @@ to_byte_scanner :: proc(s: Stream) -> (b: Byte_Scanner, ok: bool = true) {
 	}
 	}
 	return
 	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
 	b.stream = s
 	if s.stream_vtable == nil || s.impl_write_byte == nil {
 	if s.stream_vtable == nil || s.impl_write_byte == nil {
 		ok = false
 		ok = false
@@ -162,7 +162,7 @@ to_byte_writer :: proc(s: Stream) -> (b: Byte_Writer, ok: bool = true) {
 	return
 	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
 	r.stream = s
 	if s.stream_vtable == nil || s.impl_read_rune == nil {
 	if s.stream_vtable == nil || s.impl_read_rune == nil {
 		ok = false
 		ok = false
@@ -173,7 +173,7 @@ to_rune_reader :: proc(s: Stream) -> (r: Rune_Reader, ok: bool = true) {
 	return
 	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
 	r.stream = s
 	if s.stream_vtable != nil {
 	if s.stream_vtable != nil {
 		if s.impl_unread_rune == nil {
 		if s.impl_unread_rune == nil {

+ 1 - 2
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}
 	return io.Stream{stream_vtable=_builder_stream_vtable, stream_data=b}
 }
 }
 to_writer :: proc(b: ^Builder) -> io.Writer {
 to_writer :: proc(b: ^Builder) -> io.Writer {
-	w, _ := io.to_writer(to_stream(b))
-	return w
+	return io.to_writer(to_stream(b))
 }
 }
 
 
 
 

+ 1 - 1
core/testing/runner.odin

@@ -18,7 +18,7 @@ end_t :: proc(t: ^T) {
 
 
 runner :: proc(internal_tests: []Internal_Test) -> bool {
 runner :: proc(internal_tests: []Internal_Test) -> bool {
 	stream := os.stream_from_handle(os.stdout)
 	stream := os.stream_from_handle(os.stdout)
-	w, _ := io.to_writer(stream)
+	w := io.to_writer(stream)
 
 
 	t := &T{}
 	t := &T{}
 	t.w = w
 	t.w = w