Struct RootShell

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

Represents a shell with root privileges.

Implementations§

Source§

impl RootShell

Implementation of RootShell

Source

pub fn new() -> Option<Self>

Creates a new root shell. Defaults to pkexec as super user provider and sh as shell. Returns None if the root shell could not be created.

§Example
use super_shell::RootShell;
let mut root_shell = RootShell::new().expect("Failed to crate root shell");
println!("{}", root_shell.execute("echo Hello $USER"));
Source

pub fn new_custom(super_user_provider: &str, shell: &str) -> Option<Self>

Creates a new root shell with the specified super user provider and shell. Returns None if the root shell could not be created. sudo as an interactive super user provider is currently not supported.

§Parameter
  • super_user_provider - The command to use to get super user privileges
  • shell - The shell to use
§Example
use super_shell::RootShell;
let mut root_shell = RootShell::new_custom("gksu", "bash").expect("Failed to crate root shell");
println!("{}", root_shell.execute("echo Hello $USER"));
Source

pub fn execute(&mut self, command: impl AsRef<str>) -> String

Executes a command in the root shell and returns the output trimmed. Blocks the current thread until the command is finished.

§Parameter
  • command - The command to execute
§Example
use super_shell::RootShell;
let mut root_shell = RootShell::new().expect("Failed to crate root shell");
assert!(root_shell.execute("echo Hello $USER").trim().eq("Hello root"));
Source

pub fn exit(&mut self)

Exits the root shell and waits for the process to finish.

Trait Implementations§

Source§

impl Drop for RootShell

Drop implementation for RootShell.

Source§

fn drop(&mut self)

Exits the root shell and waits for the process to finish.

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.