pub trait FileSystem: Send + Sync {
// Required methods
fn search<'life0, 'life1, 'async_trait>(
&'life0 self,
search: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn view<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
view_range: Option<(u32, u32)>,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn str_replace<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
path: &'life1 str,
old_str: &'life2 str,
new_str: &'life3 str,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait;
fn insert<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
path: &'life1 str,
insert_line: u32,
insert_text: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn create<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
path: &'life1 str,
file_text: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
// Provided method
fn list_directory<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<String>, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
}Expand description
Trait for implementing filesystem operations.
Provides an abstraction over filesystem operations that can be used by agents to interact with files and directories.
Required Methods§
Sourcefn search<'life0, 'life1, 'async_trait>(
&'life0 self,
search: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn search<'life0, 'life1, 'async_trait>(
&'life0 self,
search: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Searches for files matching the given query.
Sourcefn view<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
view_range: Option<(u32, u32)>,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn view<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
view_range: Option<(u32, u32)>,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Views the contents of a file, optionally within a specific line range.
§Parameters
path- The path to the file to viewview_range- Optional tuple of(start, limit)using 1-based line numbers. Returns lines wherestart <= line_number < limit. For example,(1, 4)returns lines 1, 2, and 3. Bothstartandlimitmust be >= 1.
§Errors
Returns an error if the path does not exist, is not readable, or if view_range
contains a zero value.
Sourcefn str_replace<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
path: &'life1 str,
old_str: &'life2 str,
new_str: &'life3 str,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn str_replace<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
path: &'life1 str,
old_str: &'life2 str,
new_str: &'life3 str,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Replaces occurrences of a string in a file.
Sourcefn insert<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
path: &'life1 str,
insert_line: u32,
insert_text: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn insert<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
path: &'life1 str,
insert_line: u32,
insert_text: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Inserts text at a specific line in a file.
§Parameters
path- The path to the file to modifyinsert_line- The 1-based line number where text will be inserted. Line 1 inserts before the first line. To append to the end of a file with N lines, useN + 1.new_str- The text to insert
§Errors
Returns std::io::ErrorKind::InvalidInput if insert_line is 0 or greater than
the number of lines + 1.
Sourcefn create<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
path: &'life1 str,
file_text: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn create<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
path: &'life1 str,
file_text: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Create a file or error if it already exists.
This method creates a new file with the specified content. If the file already exists,
it returns an error with std::io::ErrorKind::AlreadyExists.
§Parameters
path- The path where the file should be createdfile_text- The content to write to the new file
§Errors
Returns an error if:
- The file already exists
- Permission is denied
- Other I/O errors occur during file creation
Provided Methods§
Sourcefn list_directory<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<String>, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn list_directory<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<String>, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Lists directory entries, if path is a directory.
Implementations return Ok(None) when they cannot distinguish directory
listings from other view results.
Implementations on Foreign Types§
Source§impl FileSystem for Path<'_>
impl FileSystem for Path<'_>
Source§fn create<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
path: &'life1 str,
file_text: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn create<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
path: &'life1 str,
file_text: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Create a file within the filesystem path, ensuring it doesn’t already exist.
This implementation uses atomic file creation semantics - the file is only created if it doesn’t already exist, preventing accidental overwrites.
§Errors
Returns std::io::ErrorKind::AlreadyExists if the file already exists.
Returns other I/O errors if file creation fails for other reasons.