FileDescriptorTable

Struct FileDescriptorTable 

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

File descriptor table for managing open file descriptors

Implementations§

Source§

impl FileDescriptorTable

Source

pub fn new() -> Self

Create a new empty file descriptor table

Source

pub fn open_fd( &mut self, fd_num: i32, path: &str, read: bool, write: bool, append: bool, truncate: bool, create_new: bool, ) -> Result<(), String>

Open a file and assign it to a file descriptor number

§Arguments
  • fd_num - The file descriptor number (0-9)
  • path - Path to the file to open
  • read - Whether to open for reading
  • write - Whether to open for writing
  • append - Whether to open in append mode
  • truncate - Whether to truncate the file
§Returns
  • Ok(()) on success
  • Err(String) with error message on failure
Source

pub fn duplicate_fd( &mut self, source_fd: i32, target_fd: i32, ) -> Result<(), String>

Duplicate a file descriptor

§Arguments
  • source_fd - The source file descriptor to duplicate
  • target_fd - The target file descriptor number
§Returns
  • Ok(()) on success
  • Err(String) with error message on failure
Source

pub fn close_fd(&mut self, fd_num: i32) -> Result<(), String>

Close a file descriptor

§Arguments
  • fd_num - The file descriptor number to close
§Returns
  • Ok(()) on success
  • Err(String) with error message on failure
Source

pub fn save_fd(&mut self, fd_num: i32) -> Result<(), String>

Save the current state of a file descriptor for later restoration

§Arguments
  • fd_num - The file descriptor number to save
§Returns
  • Ok(()) on success
  • Err(String) with error message on failure
Source

pub fn restore_fd(&mut self, fd_num: i32) -> Result<(), String>

Restore a previously saved file descriptor

§Arguments
  • fd_num - The file descriptor number to restore
§Returns
  • Ok(()) on success
  • Err(String) with error message on failure
Source

pub fn deep_clone(&self) -> Result<Self, String>

Create a deep copy of the file descriptor table This duplicates all open file descriptors so they are independent of the original table

Source

pub fn save_all_fds(&mut self) -> Result<(), String>

Save all currently open file descriptors

§Returns
  • Ok(()) on success
  • Err(String) with error message on failure
Source

pub fn restore_all_fds(&mut self) -> Result<(), String>

Restore all previously saved file descriptors

§Returns
  • Ok(()) on success
  • Err(String) with error message on failure
Source

pub fn get_stdio(&self, fd_num: i32) -> Option<Stdio>

Get a file handle for a given file descriptor number

§Arguments
  • fd_num - The file descriptor number
§Returns
  • Some(Stdio) if the fd is open and can be converted to Stdio
  • None if the fd is not open or is closed
Source

pub fn get_raw_fd(&self, fd_num: i32) -> Option<RawFd>

Get the raw file descriptor number for a given fd

§Arguments
  • fd_num - The file descriptor number
§Returns
  • Some(RawFd) if the fd is open
  • None if the fd is not open or is closed
Source

pub fn is_open(&self, fd_num: i32) -> bool

Check if a file descriptor is open

§Arguments
  • fd_num - The file descriptor number
§Returns
  • true if the fd is open
  • false if the fd is closed or not tracked
Source

pub fn is_closed(&self, fd_num: i32) -> bool

Check if a file descriptor is closed

§Arguments
  • fd_num - The file descriptor number
§Returns
  • true if the fd is explicitly closed
  • false otherwise
Source

pub fn clear(&mut self)

Clear all file descriptors and saved state

Trait Implementations§

Source§

impl Debug for FileDescriptorTable

Source§

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

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

impl Default for FileDescriptorTable

Source§

fn default() -> Self

Creates the default FileDescriptorTable.

§Examples
use rush_sh::state::FileDescriptorTable;
let table = FileDescriptorTable::default();

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.