aboutsummaryrefslogtreecommitdiffstats
path: root/src/writer.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/writer.rs')
-rw-r--r--src/writer.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/writer.rs b/src/writer.rs
index 109aba9..8f79737 100644
--- a/src/writer.rs
+++ b/src/writer.rs
@@ -1,5 +1,6 @@
use snafu::ResultExt as _;
+/// Writes ttyrec frames to a `tokio::io::AsyncWrite` instance.
pub struct Writer<W> {
writer: W,
creator: crate::creator::Creator,
@@ -7,6 +8,7 @@ pub struct Writer<W> {
}
impl<W: tokio::io::AsyncWrite> Writer<W> {
+ /// Creates a new `Writer` from a `tokio::io::AsyncWrite` instance.
pub fn new(writer: W) -> Self {
Self {
writer,
@@ -15,10 +17,22 @@ impl<W: tokio::io::AsyncWrite> Writer<W> {
}
}
+ /// Generates a new ttyrec frame with the given data.
+ ///
+ /// Equivalent to calling `frame_at` and passing
+ /// `std::time::Instant::now()` as the `time` parameter.
pub fn frame(&mut self, data: &[u8]) -> crate::error::Result<()> {
self.frame_at(std::time::Instant::now(), data)
}
+ /// Generates a new ttyrec frame with the given data at the given time.
+ ///
+ /// The frame data will be stored on this object until written out by
+ /// calls to `poll_write`.
+ ///
+ /// Note that this is not guaranteed to do the correct thing unless the
+ /// `cur_time` parameters given in each `frame_at` call are
+ /// non-decreasing.
pub fn frame_at(
&mut self,
time: std::time::Instant,
@@ -30,6 +44,11 @@ impl<W: tokio::io::AsyncWrite> Writer<W> {
Ok(())
}
+ /// Attempt to write serialized ttyrec frames to the underlying writer.
+ ///
+ /// Writes data from the previous calls to `frame` and `frame_at`. Returns
+ /// `Ok(Async::Ready(()))` if all bytes were written, and
+ /// `Ok(Async::NotReady)` otherwise.
pub fn poll_write(&mut self) -> futures::Poll<(), crate::error::Error> {
loop {
if self.to_write.is_empty() {
@@ -54,6 +73,10 @@ impl<W: tokio::io::AsyncWrite> Writer<W> {
}
}
+ /// Returns `true` if there are still bytes that need to be written.
+ ///
+ /// It is only necessary to call `poll_write` if this method returns
+ /// `true`.
pub fn needs_write(&self) -> bool {
!self.to_write.is_empty()
}