conv.odin 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package io
  2. to_reader :: proc(s: Stream) -> (r: Reader, ok: bool = true) #optional_ok {
  3. r.stream = s
  4. if s.stream_vtable == nil || s.impl_read == nil {
  5. ok = false
  6. }
  7. return
  8. }
  9. to_writer :: proc(s: Stream) -> (w: Writer, ok: bool = true) #optional_ok {
  10. w.stream = s
  11. if s.stream_vtable == nil || s.impl_write == nil {
  12. ok = false
  13. }
  14. return
  15. }
  16. to_closer :: proc(s: Stream) -> (c: Closer, ok: bool = true) #optional_ok {
  17. c.stream = s
  18. if s.stream_vtable == nil || s.impl_close == nil {
  19. ok = false
  20. }
  21. return
  22. }
  23. to_flusher :: proc(s: Stream) -> (f: Flusher, ok: bool = true) #optional_ok {
  24. f.stream = s
  25. if s.stream_vtable == nil || s.impl_flush == nil {
  26. ok = false
  27. }
  28. return
  29. }
  30. to_seeker :: proc(s: Stream) -> (seeker: Seeker, ok: bool = true) #optional_ok {
  31. seeker.stream = s
  32. if s.stream_vtable == nil || s.impl_seek == nil {
  33. ok = false
  34. }
  35. return
  36. }
  37. to_read_writer :: proc(s: Stream) -> (r: Read_Writer, ok: bool = true) #optional_ok {
  38. r.stream = s
  39. if s.stream_vtable == nil || s.impl_read == nil || s.impl_write == nil {
  40. ok = false
  41. }
  42. return
  43. }
  44. to_read_closer :: proc(s: Stream) -> (r: Read_Closer, ok: bool = true) #optional_ok {
  45. r.stream = s
  46. if s.stream_vtable == nil || s.impl_read == nil || s.impl_close == nil {
  47. ok = false
  48. }
  49. return
  50. }
  51. to_read_write_closer :: proc(s: Stream) -> (r: Read_Write_Closer, ok: bool = true) #optional_ok {
  52. r.stream = s
  53. if s.stream_vtable == nil || s.impl_read == nil || s.impl_write == nil || s.impl_close == nil {
  54. ok = false
  55. }
  56. return
  57. }
  58. to_read_write_seeker :: proc(s: Stream) -> (r: Read_Write_Seeker, ok: bool = true) #optional_ok {
  59. r.stream = s
  60. if s.stream_vtable == nil || s.impl_read == nil || s.impl_write == nil || s.impl_seek == nil {
  61. ok = false
  62. }
  63. return
  64. }
  65. to_write_flusher :: proc(s: Stream) -> (w: Write_Flusher, ok: bool = true) #optional_ok {
  66. w.stream = s
  67. if s.stream_vtable == nil || s.impl_write == nil || s.impl_flush == nil {
  68. ok = false
  69. }
  70. return
  71. }
  72. to_write_flush_closer :: proc(s: Stream) -> (w: Write_Flush_Closer, ok: bool = true) #optional_ok {
  73. w.stream = s
  74. if s.stream_vtable == nil || s.impl_write == nil || s.impl_flush == nil || s.impl_close == nil {
  75. ok = false
  76. }
  77. return
  78. }
  79. to_reader_at :: proc(s: Stream) -> (r: Reader_At, ok: bool = true) #optional_ok {
  80. r.stream = s
  81. if s.stream_vtable == nil || s.impl_read_at == nil {
  82. ok = false
  83. }
  84. return
  85. }
  86. to_writer_at :: proc(s: Stream) -> (w: Writer_At, ok: bool = true) #optional_ok {
  87. w.stream = s
  88. if s.stream_vtable == nil || s.impl_write_at == nil {
  89. ok = false
  90. }
  91. return
  92. }
  93. to_reader_from :: proc(s: Stream) -> (r: Reader_From, ok: bool = true) #optional_ok {
  94. r.stream = s
  95. if s.stream_vtable == nil || s.impl_read_from == nil {
  96. ok = false
  97. }
  98. return
  99. }
  100. to_writer_to :: proc(s: Stream) -> (w: Writer_To, ok: bool = true) #optional_ok {
  101. w.stream = s
  102. if s.stream_vtable == nil || s.impl_write_to == nil {
  103. ok = false
  104. }
  105. return
  106. }
  107. to_write_closer :: proc(s: Stream) -> (w: Write_Closer, ok: bool = true) #optional_ok {
  108. w.stream = s
  109. if s.stream_vtable == nil || s.impl_write == nil || s.impl_close == nil {
  110. ok = false
  111. }
  112. return
  113. }
  114. to_write_seeker :: proc(s: Stream) -> (w: Write_Seeker, ok: bool = true) #optional_ok {
  115. w.stream = s
  116. if s.stream_vtable == nil || s.impl_write == nil || s.impl_seek == nil {
  117. ok = false
  118. }
  119. return
  120. }