Struct CommandFS

Source
pub struct CommandFS<'a> {
    pub dir: &'a Path,
    pub err_msg: String,
}

Fields§

§dir: &'a Path§err_msg: String

Implementations§

Source§

impl<'a> CommandFS<'a>

Source

pub fn new(dir: &'a str) -> Self

let mut command = CommandFS::new("/");

It will create CommandFS struct which contain two Field. file_dir (File or Directory), err_msg (For Safety every error message is store in err_msg field)

Examples found in repository?
examples/read/main.rs (line 5)
4async fn main() {
5    let mut command = CommandFS::new("/");
6    let home_dir = command.know_home_dir();
7    command.change_dir(home_dir.as_str());
8
9    let search = ".bash";
10
11    // Print every file content
12    // Method 1
13    for file in command.query_file(search, true) {
14        println!("{file}");
15        println!(
16            "{}",
17            String::from_utf8(command.read_data(file.as_str()).await).unwrap()
18        );
19        println!("{}", command.err_msg);
20    }
21
22    // Method 2
23    for file in command.query_file(search, true) {
24        println!("{file}");
25        println!(
26            "{}",
27            String::from_utf8(&mut command >> file.as_str()).unwrap()
28        );
29        println!("{}", command.err_msg);
30    }
31}
More examples
Hide additional examples
examples/write/main.rs (line 6)
4async fn main() {
5    // Method 1 For Async
6    let mut command = CommandFS::new("/");
7    let home_dir = command.know_home_dir();
8    command.change_dir(home_dir.as_str());
9    command
10        .write_data(b"It's November".to_vec(), "metadata.txt")
11        .await;
12    println!(
13        "{}",
14        String::from_utf8(command.read_data("metadata.txt").await).unwrap()
15    ); // Print Content Asynchronously
16    println!("{}", command.err_msg);
17
18    // Method 2 For Sync
19    let mut command = CommandFS::new("/");
20    command >>= home_dir.as_str();
21    command += "mydir";
22    command >>= "mydir";
23    command += ("metadata.txt", b"It's January Now");
24    println!(
25        "{}",
26        String::from_utf8(&mut command >> "metadata.txt").unwrap()
27    ); // Print Content Normally
28}
Source

pub async fn read_data(&mut self, from_file: &str) -> Vec<u8>

let mut command = CommandFS::new("/home/username"); // For Unix System
command.read_data(".bashrc"); // If you see Empty it means file Doesn't exist or something.
println!("{}", command.err_msg); // It'll print error message without any panic
Examples found in repository?
examples/read/main.rs (line 17)
4async fn main() {
5    let mut command = CommandFS::new("/");
6    let home_dir = command.know_home_dir();
7    command.change_dir(home_dir.as_str());
8
9    let search = ".bash";
10
11    // Print every file content
12    // Method 1
13    for file in command.query_file(search, true) {
14        println!("{file}");
15        println!(
16            "{}",
17            String::from_utf8(command.read_data(file.as_str()).await).unwrap()
18        );
19        println!("{}", command.err_msg);
20    }
21
22    // Method 2
23    for file in command.query_file(search, true) {
24        println!("{file}");
25        println!(
26            "{}",
27            String::from_utf8(&mut command >> file.as_str()).unwrap()
28        );
29        println!("{}", command.err_msg);
30    }
31}
More examples
Hide additional examples
examples/write/main.rs (line 14)
4async fn main() {
5    // Method 1 For Async
6    let mut command = CommandFS::new("/");
7    let home_dir = command.know_home_dir();
8    command.change_dir(home_dir.as_str());
9    command
10        .write_data(b"It's November".to_vec(), "metadata.txt")
11        .await;
12    println!(
13        "{}",
14        String::from_utf8(command.read_data("metadata.txt").await).unwrap()
15    ); // Print Content Asynchronously
16    println!("{}", command.err_msg);
17
18    // Method 2 For Sync
19    let mut command = CommandFS::new("/");
20    command >>= home_dir.as_str();
21    command += "mydir";
22    command >>= "mydir";
23    command += ("metadata.txt", b"It's January Now");
24    println!(
25        "{}",
26        String::from_utf8(&mut command >> "metadata.txt").unwrap()
27    ); // Print Content Normally
28}
Source

pub async fn write_data(&mut self, data: Vec<u8>, to_file: &'a str)

let mut command = CommandFS::new("/home/username"); // For Unix System
command.read_data(".bashrc").await; // If you see Empty it means file Doesn't exist or something.
Examples found in repository?
examples/write/main.rs (line 10)
4async fn main() {
5    // Method 1 For Async
6    let mut command = CommandFS::new("/");
7    let home_dir = command.know_home_dir();
8    command.change_dir(home_dir.as_str());
9    command
10        .write_data(b"It's November".to_vec(), "metadata.txt")
11        .await;
12    println!(
13        "{}",
14        String::from_utf8(command.read_data("metadata.txt").await).unwrap()
15    ); // Print Content Asynchronously
16    println!("{}", command.err_msg);
17
18    // Method 2 For Sync
19    let mut command = CommandFS::new("/");
20    command >>= home_dir.as_str();
21    command += "mydir";
22    command >>= "mydir";
23    command += ("metadata.txt", b"It's January Now");
24    println!(
25        "{}",
26        String::from_utf8(&mut command >> "metadata.txt").unwrap()
27    ); // Print Content Normally
28}
Source

pub fn change_dir(&mut self, dir: &'a str)

Examples found in repository?
examples/read/main.rs (line 7)
4async fn main() {
5    let mut command = CommandFS::new("/");
6    let home_dir = command.know_home_dir();
7    command.change_dir(home_dir.as_str());
8
9    let search = ".bash";
10
11    // Print every file content
12    // Method 1
13    for file in command.query_file(search, true) {
14        println!("{file}");
15        println!(
16            "{}",
17            String::from_utf8(command.read_data(file.as_str()).await).unwrap()
18        );
19        println!("{}", command.err_msg);
20    }
21
22    // Method 2
23    for file in command.query_file(search, true) {
24        println!("{file}");
25        println!(
26            "{}",
27            String::from_utf8(&mut command >> file.as_str()).unwrap()
28        );
29        println!("{}", command.err_msg);
30    }
31}
More examples
Hide additional examples
examples/write/main.rs (line 8)
4async fn main() {
5    // Method 1 For Async
6    let mut command = CommandFS::new("/");
7    let home_dir = command.know_home_dir();
8    command.change_dir(home_dir.as_str());
9    command
10        .write_data(b"It's November".to_vec(), "metadata.txt")
11        .await;
12    println!(
13        "{}",
14        String::from_utf8(command.read_data("metadata.txt").await).unwrap()
15    ); // Print Content Asynchronously
16    println!("{}", command.err_msg);
17
18    // Method 2 For Sync
19    let mut command = CommandFS::new("/");
20    command >>= home_dir.as_str();
21    command += "mydir";
22    command >>= "mydir";
23    command += ("metadata.txt", b"It's January Now");
24    println!(
25        "{}",
26        String::from_utf8(&mut command >> "metadata.txt").unwrap()
27    ); // Print Content Normally
28}
Source

pub fn step_back(&mut self, step: usize)

Source

pub async fn remove(&mut self, file: &str)

Source

pub fn rename(&mut self, from_file: &str, rename: &str)

Source§

impl<'a> CommandFS<'a>

Source

pub fn whereami(&mut self) -> &str

Source

pub fn know_home_dir(&mut self) -> String

Examples found in repository?
examples/read/main.rs (line 6)
4async fn main() {
5    let mut command = CommandFS::new("/");
6    let home_dir = command.know_home_dir();
7    command.change_dir(home_dir.as_str());
8
9    let search = ".bash";
10
11    // Print every file content
12    // Method 1
13    for file in command.query_file(search, true) {
14        println!("{file}");
15        println!(
16            "{}",
17            String::from_utf8(command.read_data(file.as_str()).await).unwrap()
18        );
19        println!("{}", command.err_msg);
20    }
21
22    // Method 2
23    for file in command.query_file(search, true) {
24        println!("{file}");
25        println!(
26            "{}",
27            String::from_utf8(&mut command >> file.as_str()).unwrap()
28        );
29        println!("{}", command.err_msg);
30    }
31}
More examples
Hide additional examples
examples/write/main.rs (line 7)
4async fn main() {
5    // Method 1 For Async
6    let mut command = CommandFS::new("/");
7    let home_dir = command.know_home_dir();
8    command.change_dir(home_dir.as_str());
9    command
10        .write_data(b"It's November".to_vec(), "metadata.txt")
11        .await;
12    println!(
13        "{}",
14        String::from_utf8(command.read_data("metadata.txt").await).unwrap()
15    ); // Print Content Asynchronously
16    println!("{}", command.err_msg);
17
18    // Method 2 For Sync
19    let mut command = CommandFS::new("/");
20    command >>= home_dir.as_str();
21    command += "mydir";
22    command >>= "mydir";
23    command += ("metadata.txt", b"It's January Now");
24    println!(
25        "{}",
26        String::from_utf8(&mut command >> "metadata.txt").unwrap()
27    ); // Print Content Normally
28}
Source

pub fn dir_list(&mut self) -> Vec<String>

Source

pub fn file_list(&mut self) -> Vec<String>

Source

pub fn file_dir_list(&mut self) -> Vec<String>

Source

pub fn query_dir(&mut self, query: &'a str, accurate: bool) -> Vec<String>

Source

pub fn query_file(&mut self, query: &'a str, accurate: bool) -> Vec<String>

Examples found in repository?
examples/read/main.rs (line 13)
4async fn main() {
5    let mut command = CommandFS::new("/");
6    let home_dir = command.know_home_dir();
7    command.change_dir(home_dir.as_str());
8
9    let search = ".bash";
10
11    // Print every file content
12    // Method 1
13    for file in command.query_file(search, true) {
14        println!("{file}");
15        println!(
16            "{}",
17            String::from_utf8(command.read_data(file.as_str()).await).unwrap()
18        );
19        println!("{}", command.err_msg);
20    }
21
22    // Method 2
23    for file in command.query_file(search, true) {
24        println!("{file}");
25        println!(
26            "{}",
27            String::from_utf8(&mut command >> file.as_str()).unwrap()
28        );
29        println!("{}", command.err_msg);
30    }
31}
Source

pub fn query_file_dir(&mut self, query: &'a str, accurate: bool) -> Vec<String>

Trait Implementations§

Source§

impl<'a> AddAssign<&'a str> for CommandFS<'a>

```rust

let mut command = CommandFS::new(“/home/username”); command += (“mydirectory”); ``` It will create Directory,

Source§

fn add_assign(&mut self, rhs: &'a str)

Performs the += operation. Read more
Source§

impl<'a> AddAssign<(&'a str, &[u8])> for CommandFS<'a>

```rust

let mut command = CommandFS::new(“/home/username”); command += (“myfile.txt”, vec![66, 108, 97, 104,32,66, 108, 97, 104,32,66, 108, 97, 104,32,66, 108, 97, 104,32].as_bytes());

      It will create Create and Write File for non sync task but different is unknown Size.
Source§

fn add_assign(&mut self, rhs: (&'a str, &[u8]))

Performs the += operation. Read more
Source§

impl<'a, const N: usize> AddAssign<(&'a str, &[u8; N])> for CommandFS<'a>

```rust

let mut command = CommandFS::new(“/home/username”); command += (“myfile.txt”, b“Blah Blah Blah Blah“);

      It will create Create and Write File for non sync task for known Size.
Source§

fn add_assign(&mut self, rhs: (&'a str, &[u8; N]))

Performs the += operation. Read more
Source§

impl<'a> ShlAssign<usize> for CommandFS<'a>

Source§

fn shl_assign(&mut self, rhs: usize)

Performs the <<= operation. Read more
Source§

impl<'a> Shr<&str> for &mut CommandFS<'a>

Source§

type Output = Vec<u8>

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: &str) -> Self::Output

Performs the >> operation. Read more
Source§

impl<'a> ShrAssign<&str> for CommandFS<'a>

Source§

fn shr_assign(&mut self, rhs: &str)

Performs the >>= operation. Read more
Source§

impl<'a> SubAssign<&str> for CommandFS<'a>

Source§

fn sub_assign(&mut self, rhs: &str)

Performs the -= operation. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for CommandFS<'a>

§

impl<'a> RefUnwindSafe for CommandFS<'a>

§

impl<'a> Send for CommandFS<'a>

§

impl<'a> Sync for CommandFS<'a>

§

impl<'a> Unpin for CommandFS<'a>

§

impl<'a> UnwindSafe for CommandFS<'a>

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.