pub fn reverse_file<W: Write, P: AsRef<Path>>(
writer: &mut W,
path: Option<P>,
separator: u8,
) -> Result<()>
Expand description
Write the reversed content from path
into writer
, last line first.
If path
is Some(_)
, read from the file at the specified path.
If path
is None
, read from stdin
instead.
separator
is used to partition the content into lines.
This is normally the newline character, b'\n'
.
Internally it uses the following instruction set extensions to enable SIMD acceleration if available at runtime:
- AVX2/LZCNT(ABM)/BMI2 on x64/x64_84
- NEON on AArch64
ยงExample
use tac_k::reverse_file;
use std::path::Path;
// Read from `README.md` file, separated by '.'.
let mut result = vec![];
reverse_file(&mut result, Some("README.md"), b'.').unwrap();
assert!(std::str::from_utf8(&result).is_ok());
// Read from stdin.
let mut result = vec![];
reverse_file(&mut result, None::<&str>, b'.').unwrap();
assert!(result.is_empty());