[−][src]Function fcc::ends_with_newline
pub fn ends_with_newline(f: &mut File) -> Result<bool>
Checks if a given file ends with newline.
This function returns Ok(true)
if the given file ends with
a newline \n
, or returns Ok(false)
if the given file does
not end with a newline `\n'.
Errors
This function has the same error semantics as get_last_byte
,
except that if the given file is empty, it will return Ok(false)
rather than return an error variant of ErrorKind::SeekNegative
.
Examples
use fcc::ends_with_newline; use std::fs::File; use std::io::prelude::*; fn main() -> std::io::Result<()> { let mut f = File::create("foo.txt")?; f.write_all(b"Hello world!")?; assert_eq!(ends_with_newline(&mut f).unwrap(), false); f.write_all(b"Hello world!\n")?; assert_eq!(ends_with_newline(&mut f).unwrap(), true); Ok(()) }