pub struct Writer<W: Write> {
pub wtr: BufWriter<W>,
/* private fields */
}
Expand description
A writer for a refer file.
It’s a simple wrapper of a io::BufWriter, along with a line number tracker to help track errors when parsing the input.
Fields§
§wtr: BufWriter<W>
Implementations§
Source§impl Writer<File>
impl Writer<File>
Sourcepub fn from_path<P: AsRef<Path>>(path: P) -> Result<Writer<File>, Error>
pub fn from_path<P: AsRef<Path>>(path: P) -> Result<Writer<File>, Error>
Build a refer writer that writes data to the given file path. The file is truncated if it already exists.
If there was a problem opening the file at the given path, then this returns the corresponding error.
§Example
use std::error::Error;
use refer::Writer;
fn example() -> Result<(), Box<dyn Error>> {
let mut wtr = Writer::from_path("foo.refer")?;
wtr.write_record(vec!["%A Brown, M", "%J PNAS"])?;
wtr.write_record(vec!["%A Twyford, A. D.", "%J PNAS"])?;
wtr.flush()?;
Ok(())
}
Source§impl<W: Write> Writer<W>
impl<W: Write> Writer<W>
Sourcepub fn new(wtr: W) -> Writer<W>
pub fn new(wtr: W) -> Writer<W>
Create a new refer writer.
§Example
use std::error::Error;
use refer::Writer;
fn example() -> Result<(), Box<dyn Error>> {
let mut wtr = Writer::new(vec![]);
wtr.write_record(vec!["%A Brown, M", "%J PNAS"])?;
wtr.write_record(vec!["%A Twyford, A. D.", "%J PNAS"])?;
let data = String::from_utf8(wtr.into_inner()?)?;
assert_eq!(data, "%A Brown, M\n%J PNAS\n\n%A Twyford, A. D.\n%J PNAS\n\n");
Ok(())
}
Sourcepub fn write_record<I, T>(&mut self, record: I) -> Result<(), Error>
pub fn write_record<I, T>(&mut self, record: I) -> Result<(), Error>
The main function used to write a record to an output buffer.
Sourcepub fn into_inner(self) -> StdResult<W, IntoInnerError<BufWriter<W>>>
pub fn into_inner(self) -> StdResult<W, IntoInnerError<BufWriter<W>>>
Flush the contents of the current buffer and return the underlying writer.
Auto Trait Implementations§
impl<W> Freeze for Writer<W>where
W: Freeze,
impl<W> RefUnwindSafe for Writer<W>where
W: RefUnwindSafe,
impl<W> Send for Writer<W>where
W: Send,
impl<W> Sync for Writer<W>where
W: Sync,
impl<W> Unpin for Writer<W>where
W: Unpin,
impl<W> UnwindSafe for Writer<W>where
W: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more