Trait Program

Source
pub trait Program:
    Sized
    + Debug
    + Run {
    type Command: Command;

    // Required methods
    fn parse<R: BufRead>(reader: R) -> Result<Self>;
    fn commands(&self) -> &[Self::Command];
}
Expand description

A program is as large as a file or as small as a line.

Each program is to be treated as a complete single language entity, with the explicit exception of {#} blocks, which act as bridges between programs.

§Working Thoughts

  • Is simply iterating a collection of commands really the correct semantics for all the types of programs we want?
  • What language information do we still need to store?

Required Associated Types§

Source

type Command: Command

The type of each of this program’s commands.

Required Methods§

Source

fn parse<R: BufRead>(reader: R) -> Result<Self>

Parse a whole program from the given reader.

Source

fn commands(&self) -> &[Self::Command]

Return a list of all the commands in this program.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Program for oursh::program::basic::Program

Source§

impl Program for oursh::program::posix::ast::Program

The syntax and semantics of a single POSIX command.

use std::io::Read;
use oursh::program::Program as ProgramTrait;
use oursh::program::posix::ast::Program;

assert!(Program::parse(b"ls" as &[u8]).is_ok());