conv.odin 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package io
  2. to_reader :: proc(s: Stream) -> (r: Reader, ok: bool = true) #optional_ok {
  3. r = s
  4. ok = .Read in query(s)
  5. return
  6. }
  7. to_writer :: proc(s: Stream) -> (w: Writer, ok: bool = true) #optional_ok {
  8. w = s
  9. ok = .Write in query(s)
  10. return
  11. }
  12. to_closer :: proc(s: Stream) -> (c: Closer, ok: bool = true) #optional_ok {
  13. c = s
  14. ok = .Close in query(s)
  15. return
  16. }
  17. to_flusher :: proc(s: Stream) -> (f: Flusher, ok: bool = true) #optional_ok {
  18. f = s
  19. ok = .Flush in query(s)
  20. return
  21. }
  22. to_seeker :: proc(s: Stream) -> (seeker: Seeker, ok: bool = true) #optional_ok {
  23. seeker = s
  24. ok = .Seek in query(s)
  25. return
  26. }
  27. to_read_writer :: proc(s: Stream) -> (r: Read_Writer, ok: bool = true) #optional_ok {
  28. r = s
  29. ok = query(s) >= {.Read, .Write}
  30. return
  31. }
  32. to_read_closer :: proc(s: Stream) -> (r: Read_Closer, ok: bool = true) #optional_ok {
  33. r = s
  34. ok = query(s) >= {.Read, .Close}
  35. return
  36. }
  37. to_read_write_closer :: proc(s: Stream) -> (r: Read_Write_Closer, ok: bool = true) #optional_ok {
  38. r = s
  39. ok = query(s) >= {.Read, .Write, .Close}
  40. return
  41. }
  42. to_read_write_seeker :: proc(s: Stream) -> (r: Read_Write_Seeker, ok: bool = true) #optional_ok {
  43. r = s
  44. ok = query(s) >= {.Read, .Write, .Seek}
  45. return
  46. }
  47. to_write_flusher :: proc(s: Stream) -> (w: Write_Flusher, ok: bool = true) #optional_ok {
  48. w = s
  49. ok = query(s) >= {.Write, .Flush}
  50. return
  51. }
  52. to_write_flush_closer :: proc(s: Stream) -> (w: Write_Flush_Closer, ok: bool = true) #optional_ok {
  53. w = s
  54. ok = query(s) >= {.Write, .Flush, .Close}
  55. return
  56. }
  57. to_reader_at :: proc(s: Stream) -> (r: Reader_At, ok: bool = true) #optional_ok {
  58. r = s
  59. ok = query(s) >= {.Read_At}
  60. return
  61. }
  62. to_writer_at :: proc(s: Stream) -> (w: Writer_At, ok: bool = true) #optional_ok {
  63. w = s
  64. ok = query(s) >= {.Write_At}
  65. return
  66. }
  67. to_write_closer :: proc(s: Stream) -> (w: Write_Closer, ok: bool = true) #optional_ok {
  68. w = s
  69. ok = query(s) >= {.Write, .Close}
  70. return
  71. }
  72. to_write_seeker :: proc(s: Stream) -> (w: Write_Seeker, ok: bool = true) #optional_ok {
  73. w = s
  74. ok = query(s) >= {.Write, .Seek}
  75. return
  76. }