pub struct VirtualMachineBuilder { /* private fields */ }
Expand description

VirtualMachineBuilder is a builder for the VirtualMachine struct.

This builder allows you to set the program and tape_size for a VirtualMachine before building it. Both program and tape_size are optional. If they’re not provided, the VirtualMachine will be initialized with default values.

Examples

use brainfoamkit_lib::{
    Program,
    VirtualMachineBuilder,
};
let program = Program::default();
let vm = VirtualMachineBuilder::default()
    .program(program)
    .tape_size(1024)
    .build();

Implementations§

source§

impl VirtualMachineBuilder

source

pub const fn new() -> Self

Creates a new VirtualMachineBuilder with default values.

This function returns a new VirtualMachineBuilder with program and tape_size set to None. These values can be set later using the builder’s methods.

Returns

A new VirtualMachineBuilder with default values.

Examples
use brainfoamkit_lib::VirtualMachineBuilder;

let builder = VirtualMachineBuilder::new();
source

pub fn program(self, program: Program) -> Self

Set the program to be run by the virtual machine.

Arguments
  • program - The program to be run by the virtual machine.
Returns
  • Builder by value with the program set.
Examples
use brainfoamkit_lib::{
    Program,
    VirtualMachineBuilder,
};

let program = Program::from_string("++++++[>++++++++++<-]>+++++.");
let vm = VirtualMachineBuilder::new().program(program).build();

assert_eq!(
    vm.program(),
    Program::from_string("++++++[>++++++++++<-]>+++++.")
);
source

pub const fn tape_size(self, tape_size: usize) -> Self

Set the size of the tape to be used by the virtual machine. The default size is 30,000.

Arguments
  • tape_size - The size of the tape to be used by the virtual machine.
Returns
  • Builder by value with the tape size set.
Examples
use brainfoamkit_lib::VirtualMachineBuilder;

let vm = VirtualMachineBuilder::new().tape_size(100).build();

assert_eq!(vm.length(), 100);
source

pub fn build(self) -> VirtualMachine

Build the virtual machine.

Returns
  • The virtual machine.
Examples
use brainfoamkit_lib::{
    Program,
    VirtualMachineBuilder,
};

let program = Program::from_string("++++++[>++++++++++<-]>+++++.");
let vm = VirtualMachineBuilder::new()
    .program(program)
    .tape_size(100)
    .build();

Trait Implementations§

source§

impl Default for VirtualMachineBuilder

source§

fn default() -> VirtualMachineBuilder

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>,

§

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>,

§

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.