use std::io;
use std::path::{Path, PathBuf};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum OpenMode {
Input,
Output,
Append,
Random,
Binary,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AccessMode {
Read,
Write,
ReadWrite,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LockMode {
Shared,
LockRead,
LockWrite,
LockReadWrite,
}
#[derive(Debug, Clone)]
pub struct OpenFile {
pub number: i16,
pub path: String,
pub mode: OpenMode,
pub access: AccessMode,
pub lock: LockMode,
pub record_length: i32,
pub position: i64,
pub width: i16,
pub print_column: usize,
}
pub trait FileBackend: Send {
fn as_any(&self) -> &dyn std::any::Any;
fn as_any_mut(&mut self) -> &mut dyn std::any::Any;
fn open(
&mut self,
path: &Path,
mode: OpenMode,
access: AccessMode,
lock: LockMode,
record_length: i32,
) -> io::Result<OpenFile>;
fn close(&mut self, file: &OpenFile) -> io::Result<()>;
fn read(&mut self, file: &mut OpenFile, buf: &mut [u8]) -> io::Result<usize>;
fn write(&mut self, file: &mut OpenFile, buf: &[u8]) -> io::Result<usize>;
fn seek(&mut self, file: &mut OpenFile, position: i64) -> io::Result<i64>;
fn file_len(&mut self, path: &Path) -> io::Result<i64>;
fn file_exists(&mut self, path: &Path) -> bool;
fn file_dir(&mut self, path: &Path, pattern: &str, attributes: i16) -> io::Result<Vec<String>>;
fn position(&self, file: &OpenFile) -> i64;
fn lof(&mut self, file: &OpenFile) -> io::Result<i64>;
fn copy_file(&mut self, src: &Path, dst: &Path) -> io::Result<()>;
fn rename_file(&mut self, old_path: &Path, new_path: &Path) -> io::Result<()>;
fn remove_file(&mut self, path: &Path) -> io::Result<()>;
fn create_dir(&mut self, path: &Path) -> io::Result<()>;
fn remove_dir(&mut self, path: &Path) -> io::Result<()>;
fn get_attrs(&mut self, path: &Path) -> io::Result<i16>;
fn set_attrs(&mut self, path: &Path, attrs: i16) -> io::Result<()>;
fn file_datetime(&mut self, path: &Path) -> io::Result<std::time::SystemTime>;
fn current_dir(&mut self) -> io::Result<PathBuf>;
fn set_current_dir(&mut self, path: &Path) -> io::Result<()>;
fn drives(&self) -> Vec<char>;
fn current_dir_for_drive(&mut self, drive: char) -> io::Result<PathBuf>;
fn set_current_drive(&mut self, drive: char) -> io::Result<()>;
fn lock_file(&mut self, path: &Path, record_range: Option<(i32, i32)>) -> io::Result<()>;
fn unlock_file(&mut self, path: &Path, record_range: Option<(i32, i32)>) -> io::Result<()>;
}