[go: up one dir, main page]

Struct Roff

Source
pub struct Roff { /* private fields */ }
Expand description

A ROFF document, consisting of lines.

Lines are either control lines (requests that are built in, or invocations of macros), or text lines.

§Example

let doc = Roff::new()
    .control("TH", ["FOO", "1"])
    .control("SH", ["NAME"])
    .text([roman("foo - do a foo thing")])
    .render();
assert!(doc.ends_with(".TH FOO 1\n.SH NAME\nfoo \\- do a foo thing\n"));

Implementations§

Source§

impl Roff

Source

pub fn new() -> Self

Instantiate a Roff

Source

pub fn control<'a>( &mut self, name: impl Into<String>, args: impl IntoIterator<Item = &'a str>, ) -> &mut Self

Append a control line.

The line consist of the name of a built-in command or macro, and some number of arguments. Arguments that contain spaces will be enclosed with double quotation marks.

Source

pub fn text(&mut self, inlines: impl Into<Vec<Inline>>) -> &mut Self

Append a text line.

The line will be rendered in a way that ensures it can’t be interpreted as a control line. The caller does not need to ensure, for example, that the line doesn’t start with a period (“.”) or an apostrophe (“'”).

Source

pub fn render(&self) -> String

Render as ROFF source text that can be fed to a ROFF implementation.

Source

pub fn to_writer(&self, w: &mut dyn Write) -> Result<(), Error>

Write to a writer.

Source

pub fn to_roff(&self) -> String

Render without handling apostrophes specially.

You probably want render or to_writer instead of this method.

Without special handling, apostrophes get typeset as right single quotes, including in words like “don’t”. In most situations, such as in manual pages, that’s unwanted. The other methods handle apostrophes specially to prevent it, but for completeness, and for testing, this method is provided to avoid it.

Trait Implementations§

Source§

impl Debug for Roff

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Roff

Source§

fn default() -> Roff

Returns the “default value” for a type. Read more
Source§

impl<R: Into<Roff>> Extend<R> for Roff

Source§

fn extend<T: IntoIterator<Item = R>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<I: Into<Inline>> From<I> for Roff

Source§

fn from(other: I) -> Self

Converts to this type from the input type.
Source§

impl<R: Into<Roff>> FromIterator<R> for Roff

Source§

fn from_iter<I: IntoIterator<Item = R>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl PartialEq for Roff

Source§

fn eq(&self, other: &Roff) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Roff

Source§

impl StructuralPartialEq for Roff

Auto Trait Implementations§

§

impl Freeze for Roff

§

impl RefUnwindSafe for Roff

§

impl Send for Roff

§

impl Sync for Roff

§

impl Unpin for Roff

§

impl UnwindSafe for Roff

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.