Struct command_fs::file_handel::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

§Example
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)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
async fn main() {
    let mut command = CommandFS::new("/");
    let home_dir = command.know_home_dir();
    command.change_dir(home_dir.as_str());

    let search = ".bash";

    // Print every file content
    // Method 1
    for file in command.query_file(search, true) {
        println!("{file}");
        println!(
            "{}",
            String::from_utf8(command.read_data(file.as_str()).await).unwrap()
        );
        println!("{}", command.err_msg);
    }

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

    // Method 2 For Sync
    let mut command = CommandFS::new("/");
    command >>= home_dir.as_str();
    command += "mydir";
    command >>= "mydir";
    command += ("metadata.txt", b"It's January Now");
    println!(
        "{}",
        String::from_utf8(&mut command >> "metadata.txt").unwrap()
    ); // Print Content Normally
}
source

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

§Example
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)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
async fn main() {
    let mut command = CommandFS::new("/");
    let home_dir = command.know_home_dir();
    command.change_dir(home_dir.as_str());

    let search = ".bash";

    // Print every file content
    // Method 1
    for file in command.query_file(search, true) {
        println!("{file}");
        println!(
            "{}",
            String::from_utf8(command.read_data(file.as_str()).await).unwrap()
        );
        println!("{}", command.err_msg);
    }

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

    // Method 2 For Sync
    let mut command = CommandFS::new("/");
    command >>= home_dir.as_str();
    command += "mydir";
    command >>= "mydir";
    command += ("metadata.txt", b"It's January Now");
    println!(
        "{}",
        String::from_utf8(&mut command >> "metadata.txt").unwrap()
    ); // Print Content Normally
}
source

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

§Example
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)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
async fn main() {
    // Method 1 For Async
    let mut command = CommandFS::new("/");
    let home_dir = command.know_home_dir();
    command.change_dir(home_dir.as_str());
    command
        .write_data(b"It's November".to_vec(), "metadata.txt")
        .await;
    println!(
        "{}",
        String::from_utf8(command.read_data("metadata.txt").await).unwrap()
    ); // Print Content Asynchronously
    println!("{}", command.err_msg);

    // Method 2 For Sync
    let mut command = CommandFS::new("/");
    command >>= home_dir.as_str();
    command += "mydir";
    command >>= "mydir";
    command += ("metadata.txt", b"It's January Now");
    println!(
        "{}",
        String::from_utf8(&mut command >> "metadata.txt").unwrap()
    ); // Print Content Normally
}
source

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

Examples found in repository?
examples/read/main.rs (line 7)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
async fn main() {
    let mut command = CommandFS::new("/");
    let home_dir = command.know_home_dir();
    command.change_dir(home_dir.as_str());

    let search = ".bash";

    // Print every file content
    // Method 1
    for file in command.query_file(search, true) {
        println!("{file}");
        println!(
            "{}",
            String::from_utf8(command.read_data(file.as_str()).await).unwrap()
        );
        println!("{}", command.err_msg);
    }

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

    // Method 2 For Sync
    let mut command = CommandFS::new("/");
    command >>= home_dir.as_str();
    command += "mydir";
    command >>= "mydir";
    command += ("metadata.txt", b"It's January Now");
    println!(
        "{}",
        String::from_utf8(&mut command >> "metadata.txt").unwrap()
    ); // Print Content Normally
}
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)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
async fn main() {
    let mut command = CommandFS::new("/");
    let home_dir = command.know_home_dir();
    command.change_dir(home_dir.as_str());

    let search = ".bash";

    // Print every file content
    // Method 1
    for file in command.query_file(search, true) {
        println!("{file}");
        println!(
            "{}",
            String::from_utf8(command.read_data(file.as_str()).await).unwrap()
        );
        println!("{}", command.err_msg);
    }

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

    // Method 2 For Sync
    let mut command = CommandFS::new("/");
    command >>= home_dir.as_str();
    command += "mydir";
    command >>= "mydir";
    command += ("metadata.txt", b"It's January Now");
    println!(
        "{}",
        String::from_utf8(&mut command >> "metadata.txt").unwrap()
    ); // Print Content Normally
}
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)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
async fn main() {
    let mut command = CommandFS::new("/");
    let home_dir = command.know_home_dir();
    command.change_dir(home_dir.as_str());

    let search = ".bash";

    // Print every file content
    // Method 1
    for file in command.query_file(search, true) {
        println!("{file}");
        println!(
            "{}",
            String::from_utf8(command.read_data(file.as_str()).await).unwrap()
        );
        println!("{}", command.err_msg);
    }

    // Method 2
    for file in command.query_file(search, true) {
        println!("{file}");
        println!(
            "{}",
            String::from_utf8(&mut command >> file.as_str()).unwrap()
        );
        println!("{}", command.err_msg);
    }
}
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>

§Example

```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, const N: usize> AddAssign<(&'a str, &[u8; N])> for CommandFS<'a>

§Example

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

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>

§

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

§

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.