File-sink-reopen-truncate
Reopen a FileSink in truncate mode. This helper is the explicit truncate-oriented recovery or reset shortcut on the direct sink.
Interface
pub fn FileSink::reopen_truncate(self : FileSink) -> Bool {input
self : FileSink- File sink that should be reopened in truncate mode.
output
Bool- Whether reopen succeeded.
Explanation
Detailed rules explaining key parameters and behaviors
- This helper is a specialized shortcut over
reopen(append=Some(false)). - Reopen behavior is fixed to truncate mode.
- The stored append policy is updated to
falseas part of the reopen path. - On failure, the sink remains unavailable and
open_failuresis incremented.
How to Use
Here are some specific examples provided.
When Need A Fresh Output File
When a direct runtime file should be reopened from an empty state:
ignore(sink.reopen_truncate())In this example, reopen behavior truncates the file before future writes continue.
When Want An Explicit Truncate Shortcut
When code should make destructive reopen intent obvious:
let ok = sink.reopen_truncate()In this example, the call site expresses reset-style reopen behavior directly.
Error Case
e.g.:
If callers want to preserve existing file content,
reopen_append()is the correct API.If reopen fails, the helper returns
falseand the sink stays unavailable.
Notes
Use this helper when starting from a fresh file is intentional.
Truncate-mode reopen is a stronger action than generic reopen recovery.