Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Observe file closing

Files close automatically when dropped. Call close() explicitly to observe a close error. A closed file remains a valid value without an open handle.

Run this in a scratch directory: it replaces plenty-handle.txt.

def inspect_file() -> Result[(), IoError]:
    mut file = open("plenty-handle.txt", "w")?
    print(file.closed)?
    file.close()?
    print(file.closed)?
    file.close()?
    Ok(())

def main() -> Result[(), IoError]:
    inspect_file()?
    Ok(())
False
True

Closing twice succeeds. Automatic close cannot report errors or promise durable writes.