CastWright

Struct CastWright 

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

The CastWright struct represents the main entry point for the CastWright library.

An instance of CastWright can be configured. It parses and executes CastWright scripts, and writes the resulting asciicast to a writer.

§Instantiation

To instantiate a CastWright instance, use the CastWright::new method.

§Configuration

You can then configure the instance using the following methods:

  • execute: Set whether to execute and capture the output of shell commands.
  • timestamp: Set whether to include timestamp information in the output.
  • preview: Set whether to preview the asciicast.

§Running

To parse and execute a CastWright script and write the resulting asciicast, use the run method, which takes mutable references to a reader and a writer. For better performance, a buffered writer is recommended.

§Example

use castwright::CastWright;
use std::io::BufReader;

// Input & output
let text = r#"
    $ echo "Hello, World!"
"#;
let text = text.trim();
let mut reader = BufReader::new(text.as_bytes());
let mut writer = Vec::new();
// CastWright
let castwright = CastWright::new() // Instantiation & configuration
    .execute(true)
    .preview(true);
castwright.run(&mut reader, &mut writer).unwrap(); // Running
let asciicast = String::from_utf8_lossy(&writer); // Output

If you prefer to use the default configuration:

CastWright::new().run(&mut reader, &mut writer).unwrap();
let asciicast = String::from_utf8_lossy(&writer);

Implementations§

Source§

impl CastWright

Source

pub fn new() -> Self

Create a new CastWright instance.

Source

pub const fn execute(self, execute: bool) -> Self

Set whether to execute and capture the output of shell commands.

Source

pub const fn timestamp(self, timestamp: bool) -> Self

Set whether to include timestamp information in the output.

Source

pub const fn preview(self, preview: bool) -> Self

Set whether to preview the asciicast.

Source

pub fn run( &self, reader: &mut impl BufRead, writer: &mut impl Write, ) -> Result<(), Error>

Interpret and run a CastWright script from a reader, writing the asciicast to a writer.

§Errors

This method returns an error if the script contains any syntax errors, or any errors occur during execution.

Trait Implementations§

Source§

impl Debug for CastWright

Source§

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

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

impl Default for CastWright

Source§

fn default() -> CastWright

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

Auto Trait Implementations§

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.