Files
core/test/rust/native/file.dever
T
2026-11-27 06:03:56 +00:00

68 lines
2.2 KiB
Plaintext

missing(file: dever.system.File?) (out: Bool) { out = file == null }
flow createFile(path: Text) (out: dever.system.File)
| step | kind | do |
| out | flow | dever.io.create(path) |
flow openFile(path: Text) (out: dever.system.File)
| step | kind | do |
| out | flow | dever.io.open(path) |
flow readFile(file: dever.system.File, limit: Int) (out: dever.io.ReadState)
| step | kind | do |
| out | flow | dever.io.read(file, limit) |
flow writeFile(file: dever.system.File, bytes: Bytes) ()
| step | kind | do |
| - | flow | dever.io.write(file, bytes) |
flow closeFile(file: dever.system.File) ()
| step | kind | do |
| - | flow | dever.io.close(file) |
flow createAndWrite(path: Text, bytes: Bytes) ()
| step | kind | do |
| file | flow | createFile(path) |
| alias | calc | file |
| - | flow | writeFile(alias, bytes) |
| - | flow | closeFile(file) |
flow readSome(path: Text, limit: Int) (out: dever.io.ReadState)
| step | kind | do |
| file | flow | openFile(path) |
| out | flow | readFile(file, limit) |
| - | flow | closeFile(file) |
flow offload(path: Text, limit: Int) (out: dever.io.ReadState)
| step | kind | do |
| out | calc | blocking(readSome(path, limit)) |
flow spawned(path: Text, limit: Int) (out: dever.io.ReadState)
| step | kind | do |
| task | calc | run(readSome(path, limit)) |
| out | calc | wait(task) |
flow fault(path: Text, value: Int) (out: Int)
| step | kind | do |
| file | flow | openFile(path) |
| data | flow | readFile(file, 1) |
| out | calc | value + 1 |
flow failAfterOpen(path: Text) ()
| step | kind | do |
| file | flow | openFile(path) |
| - | flow | closeFile(file) |
| - | flow | closeFile(file) |
type Attempt { Ready(value: dever.io.ReadState), error Failed(value: dever.io.ReadResult), error Missing(value: dever.io.OpenResult), error Closed(value: dever.io.CloseResult) }
rule accepted(value: Attempt) (out: Bool) recover("report whether the requested file could be read")
| value | out |
| Ready(state) | true |
| Failed(error) | false |
| Missing(error) | false |
| Closed(error) | false |
flow captured(path: Text, limit: Int) (out: Bool)
| step | kind | do |
| attempt: Attempt | flow | result(readSome(path, limit)) |
| out | rule | accepted(attempt) |