aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-12-04 03:50:22 -0500
committerJesse Luehrs <doy@tozt.net>2021-12-04 03:50:22 -0500
commit57f245da290fee5a1cb2e9526fd30df3a2fb379d (patch)
tree9a881db398840a976cb9af30fbea348535fe5100 /src
parent3ba8bad931571f9a2586dd02d50415dc8428ed41 (diff)
downloadttyrec-57f245da290fee5a1cb2e9526fd30df3a2fb379d.tar.gz
ttyrec-57f245da290fee5a1cb2e9526fd30df3a2fb379d.zip
fix doc links0.3.0
Diffstat (limited to 'src')
-rw-r--r--src/blocking/reader.rs12
-rw-r--r--src/blocking/writer.rs12
-rw-r--r--src/creator.rs23
-rw-r--r--src/frame.rs4
-rw-r--r--src/lib.rs10
-rw-r--r--src/parser.rs13
-rw-r--r--src/reader.rs13
-rw-r--r--src/writer.rs13
8 files changed, 53 insertions, 47 deletions
diff --git a/src/blocking/reader.rs b/src/blocking/reader.rs
index 86c348d..609c393 100644
--- a/src/blocking/reader.rs
+++ b/src/blocking/reader.rs
@@ -1,4 +1,4 @@
-/// Reads ttyrec frames from a `std::io::Read` instance.
+/// Reads ttyrec frames from a [`std::io::Read`] instance.
pub struct Reader<T: std::io::Read> {
input: T,
parser: crate::Parser,
@@ -6,7 +6,7 @@ pub struct Reader<T: std::io::Read> {
}
impl<T: std::io::Read> Reader<T> {
- /// Creates a new `Reader` from a `std::io::Read` instance.
+ /// Creates a new [`Reader`] from a [`std::io::Read`] instance.
pub fn new(input: T) -> Self {
Self {
input,
@@ -18,9 +18,9 @@ impl<T: std::io::Read> Reader<T> {
/// Returns the next parsed frame from the input stream.
///
/// # Errors
- /// * `crate::Error::EOF`: The input stream has been closed.
- /// * `crate::Error::Read`: There was an error reading from the input
- /// stream.
+ /// * [`Error::EOF`](crate::Error::EOF): The input stream has been closed.
+ /// * [`Error::Read`](crate::Error::Read): There was an error reading from
+ /// the input stream.
pub fn read_frame(&mut self) -> crate::Result<crate::Frame> {
loop {
if let Some(frame) = self.parser.next_frame() {
@@ -39,7 +39,7 @@ impl<T: std::io::Read> Reader<T> {
/// How much the timestamps in this file should be offset by.
///
- /// See `Parser::offset`.
+ /// See [`Parser::offset`](crate::Parser::offset).
pub fn offset(&self) -> Option<std::time::Duration> {
self.parser.offset()
}
diff --git a/src/blocking/writer.rs b/src/blocking/writer.rs
index 5dade25..c9fdb7d 100644
--- a/src/blocking/writer.rs
+++ b/src/blocking/writer.rs
@@ -1,11 +1,11 @@
-/// Writes ttyrec frames to a `std::io::Write` instance.
+/// Writes ttyrec frames to a [`std::io::Write`] instance.
pub struct Writer<T: std::io::Write> {
output: T,
creator: crate::Creator,
}
impl<T: std::io::Write> Writer<T> {
- /// Creates a new `Writer` from a `std::io::Write` instance.
+ /// Creates a new [`Writer`] from a [`std::io::Write`] instance.
pub fn new(output: T) -> Self {
Self {
output,
@@ -17,8 +17,8 @@ impl<T: std::io::Write> Writer<T> {
/// given data.
///
/// # Errors
- /// * `crate::Error::Write`: There was an error writing to the input
- /// stream.
+ /// * [`Error::Write`](crate::Error::Write): There was an error writing to
+ /// the input stream.
pub fn frame(&mut self, data: &[u8]) -> crate::Result<()> {
self.frame_at(std::time::Instant::now(), data)
}
@@ -27,8 +27,8 @@ impl<T: std::io::Write> Writer<T> {
/// data.
///
/// # Errors
- /// * `crate::Error::Write`: There was an error writing to the input
- /// stream.
+ /// * [`crate::Error::Write`](crate::Error::Write): There was an error
+ /// writing to the input stream.
pub fn frame_at(
&mut self,
cur_time: std::time::Instant,
diff --git a/src/creator.rs b/src/creator.rs
index f4745cc..590d282 100644
--- a/src/creator.rs
+++ b/src/creator.rs
@@ -1,35 +1,36 @@
/// Creates ttyrec frames.
///
/// A ttyrec file is a stream of concatenated frames. This struct creates
-/// `Frame` objects, which can be serialized to bytes using their `try_from`
-/// implementation, and then a ttyrec file can be generated by concatenating
-/// those byte strings.
+/// [`Frame`](crate::Frame) objects, which can be serialized to bytes using
+/// their `try_from` implementation, and then a ttyrec file can be generated
+/// by concatenating those byte strings.
#[derive(Debug, Clone)]
pub struct Creator {
base_time: Option<std::time::Instant>,
}
impl Creator {
- /// Creates a new `Creator` instance.
+ /// Creates a new [`Creator`] instance.
#[must_use]
pub fn new() -> Self {
Self::default()
}
- /// Returns a new `Frame` object containing the given data.
+ /// Returns a new [`Frame`](crate::Frame) object containing the given
+ /// data.
///
- /// Equivalent to calling `frame_at` and passing
- /// `std::time::Instant::now()` as the `cur_time` parameter.
+ /// Equivalent to calling [`frame_at`](Self::frame_at) and passing
+ /// [`std::time::Instant::now()`] as the `cur_time` parameter.
pub fn frame(&mut self, data: &[u8]) -> crate::frame::Frame {
self.frame_at(std::time::Instant::now(), data)
}
- /// Returns a new `Frame` object containing the given data at the given
- /// time.
+ /// Returns a new [`Frame`](crate::Frame) object containing the given data
+ /// at the given time.
///
/// 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.
+ /// `cur_time` parameters given in each [`frame_at`](Self::frame_at) call
+ /// are non-decreasing.
#[allow(clippy::missing_panics_doc)]
pub fn frame_at(
&mut self,
diff --git a/src/frame.rs b/src/frame.rs
index 71b3988..5996409 100644
--- a/src/frame.rs
+++ b/src/frame.rs
@@ -5,8 +5,8 @@
/// is relevant. The base timestamp can be anything (common choices are 0 or
/// the actual time that the frame was generated).
///
-/// Frame objects are typically created via the `Creator`, `Parser`, or
-/// `Reader` classes.
+/// Frame objects are typically created via the [`Creator`](crate::Creator),
+/// [`Parser`](crate::Parser), or [`Reader`](crate::Reader) classes.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Frame {
/// Amount of time passed since the start of the ttyrec file.
diff --git a/src/lib.rs b/src/lib.rs
index 5efd824..c7a43ec 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -3,11 +3,13 @@
//!
//! `Parser` and `Creator` can be used to read and write files manually, and
//! `Reader` and `Writer` are helpers to provide a nicer API for asynchronous
-//! applications using `tokio`.
+//! applications using futures. Additionally, `blocking::Reader` and
+//! `blocking::Writer` provide a similar API for non-asynchronous
+//! applications.
//!
-//! If you are not using `tokio`, the `tokio` dependencies can be removed by
-//! building with `default_features = false` (by default, the `"async"`
-//! feature is enabled which provides `tokio` support).
+//! If you do not need the async API, the `futures` dependency can be removed
+//! by building with `default_features = false` (by default, the `"async"`
+//! feature is enabled).
// XXX this is broken with ale
// #![warn(clippy::cargo)]
diff --git a/src/parser.rs b/src/parser.rs
index 126eae3..9887b38 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -22,9 +22,10 @@ impl Header {
///
/// Designed to be able to be used in a streaming/asynchronous fashion. As you
/// read bytes from the ttyrec stream (whether from a file or whatever else),
-/// call the `add_bytes` method to add them to the internal buffer. At any
-/// point, you can call `next_frame` to then return the next complete frame if
-/// one has been read.
+/// call the [`add_bytes`](Parser::add_bytes) method to add them to the
+/// internal buffer. At any point, you can call
+/// [`next_frame`](Parser::next_frame) to then return the next complete frame
+/// if one has been read.
#[derive(Debug, Default, Clone)]
pub struct Parser {
reading: std::collections::VecDeque<u8>,
@@ -33,7 +34,7 @@ pub struct Parser {
}
impl Parser {
- /// Create a new `Parser`.
+ /// Create a new [`Parser`](Self).
#[must_use]
pub fn new() -> Self {
Self::default()
@@ -48,7 +49,7 @@ impl Parser {
///
/// If a complete frame is found, the bytes for that frame will be removed
/// from the internal buffer and the frame object will be returned. If a
- /// complete frame is not found, this method will return `None`.
+ /// complete frame is not found, this method will return [`None`].
#[allow(clippy::missing_panics_doc)]
pub fn next_frame(&mut self) -> Option<crate::frame::Frame> {
let header = if let Some(header) = &self.read_state {
@@ -108,7 +109,7 @@ impl Parser {
/// need to take the timestamp of the first frame as the start time, and
/// each frame timestamp after that should be offset by that same amount.
///
- /// Returns `None` if no frames have been read yet.
+ /// Returns [`None`] if no frames have been read yet.
#[must_use]
pub fn offset(&self) -> Option<std::time::Duration> {
self.offset
diff --git a/src/reader.rs b/src/reader.rs
index 6641bb9..240c78e 100644
--- a/src/reader.rs
+++ b/src/reader.rs
@@ -1,6 +1,6 @@
use futures::io::AsyncReadExt as _;
-/// Reads ttyrec frames from a `futures::io::AsyncRead` instance.
+/// Reads ttyrec frames from a [`futures::io::AsyncRead`] instance.
pub struct Reader<T: futures::io::AsyncRead> {
input: T,
parser: crate::Parser,
@@ -8,7 +8,8 @@ pub struct Reader<T: futures::io::AsyncRead> {
}
impl<T: futures::io::AsyncRead + std::marker::Unpin + Send> Reader<T> {
- /// Creates a new `Reader` from a `futures::io::AsyncRead` instance.
+ /// Creates a new [`Reader`](Self) from a [`futures::io::AsyncRead`]
+ /// instance.
pub fn new(input: T) -> Self {
Self {
input,
@@ -20,9 +21,9 @@ impl<T: futures::io::AsyncRead + std::marker::Unpin + Send> Reader<T> {
/// Returns the next parsed frame from the input stream.
///
/// # Errors
- /// * `crate::Error::EOF`: The input stream has been closed.
- /// * `crate::Error::Read`: There was an error reading from the input
- /// stream.
+ /// * [`Error::EOF`](crate::Error::EOF): The input stream has been closed.
+ /// * [`Error::Read`](crate::Error::Read): There was an error reading from
+ /// the input stream.
pub async fn read_frame(&mut self) -> crate::Result<crate::Frame> {
loop {
if let Some(frame) = self.parser.next_frame() {
@@ -42,7 +43,7 @@ impl<T: futures::io::AsyncRead + std::marker::Unpin + Send> Reader<T> {
/// How much the timestamps in this file should be offset by.
///
- /// See `Parser::offset`.
+ /// See [`Parser::offset`](crate::Parser::offset).
pub fn offset(&self) -> Option<std::time::Duration> {
self.parser.offset()
}
diff --git a/src/writer.rs b/src/writer.rs
index 6975ad1..f161df0 100644
--- a/src/writer.rs
+++ b/src/writer.rs
@@ -1,13 +1,14 @@
use futures::io::AsyncWriteExt as _;
-/// Writes ttyrec frames to a `futures::io::AsyncWrite` instance.
+/// Writes ttyrec frames to a [`futures::io::AsyncWrite`] instance.
pub struct Writer<T: futures::io::AsyncWrite> {
output: T,
creator: crate::Creator,
}
impl<T: futures::io::AsyncWrite + std::marker::Unpin + Send> Writer<T> {
- /// Creates a new `Writer` from a `futures::io::AsyncWrite` instance.
+ /// Creates a new [`Writer`](Self) from a [`futures::io::AsyncWrite`]
+ /// instance.
pub fn new(output: T) -> Self {
Self {
output,
@@ -19,8 +20,8 @@ impl<T: futures::io::AsyncWrite + std::marker::Unpin + Send> Writer<T> {
/// given data.
///
/// # Errors
- /// * `crate::Error::Write`: There was an error writing to the input
- /// stream.
+ /// * [`Error::Write`](crate::Error::Write): There was an error writing to
+ /// the input stream.
pub async fn frame(&mut self, data: &[u8]) -> crate::Result<()> {
self.frame_at(std::time::Instant::now(), data).await
}
@@ -29,8 +30,8 @@ impl<T: futures::io::AsyncWrite + std::marker::Unpin + Send> Writer<T> {
/// data.
///
/// # Errors
- /// * `crate::Error::Write`: There was an error writing to the input
- /// stream.
+ /// * [`Error::Write`](crate::Error::Write): There was an error writing to
+ /// the input stream.
pub async fn frame_at(
&mut self,
cur_time: std::time::Instant,