Struct cli_sandbox::Project

source ·
pub struct Project { /* private fields */ }

Implementations§

source§

impl Project

source

pub fn new() -> Result<Self>

Creates a new Project

source

pub fn path(&self) -> &Path

Gets the std::path::Path for the Project’s temporary directory.

source

pub fn new_file<P: AsRef<Path>>( &mut self, path: P, contents: &str ) -> Result<()>

Creates a new file with a relative path to the project’s directory.

path gets redirected to the project’s real path (temporary and unknown).

source

pub fn check_file<P: AsRef<Path>>(&self, path: P, contents: &str) -> Result<()>

Checks that the contents of a file are correct. It will panic if they aren’t, and show the differences if the feature pretty_assertions is enabled

path gets redirected to the project’s real path (temporary and unknown)

Panics

Will panic if the contents of the file at path aren’t encoded as UTF-8

source

pub fn command<I, S>(&self, args: I) -> Result<Output>where I: IntoIterator<Item = S>, S: AsRef<OsStr>,

Executes a command relative to the project’s directory

source

pub fn is_bin<P: AsRef<Path>>(&self, path: P) -> bool

Checks the file signature of a file and returns true if the file in that path is an executable.

The checked file signatures are the following, if the file’s signature is any of the following, the function will return true.

  • 4D 5A
    • DOS MZ executable and descendants | (.exe, .scr, .sys, .dll, .fon, .cpl, .iec, .ime, .rs, .tsp, .mz)
  • 5A 4D
    • DOS ZM executable and descendants, rare | (.exe)
  • 7F 45 4C 46
    • ELF files
  • 64 65 78 0A 30 33 35 00
  • 4A 6F 79 21
    • Preferred Executable Format
  • 00 00 03 F3
    • Amiga Hunk executable file

Creates a symbolic link, both paths are relative to the temporary project’s path.

Panics

This function will panic if the OS can’t create a system between the two paths.

source

pub fn clean_env(&self, prefix: &str)

Cleans your environment used in the working directory (i.e. removing all environment variables that start with a prefix).


(Note that “localized” environment variables are taken into account)

Panics

This function will panic if it couldn’t get the current working directory, or; it can’t set the current working directory to the temporary project’s path, or; it can’t set the current working directory to the original working directory.

Trait Implementations§

source§

impl Debug for Project

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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.