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>
impl<'a> CommandFS<'a>
sourcepub fn new(dir: &'a str) -> Self
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
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
}
sourcepub async fn read_data(&mut self, from_file: &str) -> Vec<u8>
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
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
}
sourcepub async fn write_data(&mut self, data: Vec<u8>, to_file: &'a str)
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
}
sourcepub fn change_dir(&mut self, dir: &'a str)
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
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
}
pub fn step_back(&mut self, step: usize)
pub async fn remove(&mut self, file: &str)
pub fn rename(&mut self, from_file: &str, rename: &str)
source§impl<'a> CommandFS<'a>
impl<'a> CommandFS<'a>
pub fn whereami(&mut self) -> &str
sourcepub fn know_home_dir(&mut self) -> String
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
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
}
pub fn dir_list(&mut self) -> Vec<String>
pub fn file_list(&mut self) -> Vec<String>
pub fn file_dir_list(&mut self) -> Vec<String>
pub fn query_dir(&mut self, query: &'a str, accurate: bool) -> Vec<String>
sourcepub fn query_file(&mut self, query: &'a str, accurate: bool) -> Vec<String>
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);
}
}
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>
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)
fn add_assign(&mut self, rhs: &'a str)
Performs the
+=
operation. Read moresource§impl<'a, const N: usize> AddAssign<(&'a str, &[u8; N])> for CommandFS<'a>
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§impl<'a> ShlAssign<usize> for CommandFS<'a>
impl<'a> ShlAssign<usize> for CommandFS<'a>
source§fn shl_assign(&mut self, rhs: usize)
fn shl_assign(&mut self, rhs: usize)
Performs the
<<=
operation. Read moreAuto 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more