Rename lsdir to read_dir and dirent to dir_entry

This commit is contained in:
lumi 2025-06-26 23:24:48 +10:00
parent 862fcfe891
commit b1572cc9f1
Signed by: luaneko
GPG Key ID: 406809B8763FF07A

View File

@ -63,11 +63,11 @@ impl lb_fslib {
Ok(std::fs::write(path, contents)?) Ok(std::fs::write(path, contents)?)
} }
pub async extern "Lua-C" fn lsdir(&self, path: &str) -> Result<lb_lsdir> { pub async extern "Lua-C" fn read_dir(&self, path: &str) -> Result<lb_read_dir> {
Ok(tokio::fs::read_dir(path).await?.into()) Ok(tokio::fs::read_dir(path).await?.into())
} }
pub extern "Lua-C" fn lsdir_sync(&self, path: &str) -> Result<lb_lsdir_sync> { pub extern "Lua-C" fn read_dir_sync(&self, path: &str) -> Result<lb_read_dir_sync> {
Ok(std::fs::read_dir(path)?.into()) Ok(std::fs::read_dir(path)?.into())
} }
} }
@ -75,25 +75,25 @@ impl lb_fslib {
/// Iterator over the entries in a directory. /// Iterator over the entries in a directory.
#[derive(Debug, From)] #[derive(Debug, From)]
#[cdef] #[cdef]
pub struct lb_lsdir(#[opaque] tokio::fs::ReadDir); pub struct lb_read_dir(#[opaque] tokio::fs::ReadDir);
#[metatype] #[metatype]
impl lb_lsdir { impl lb_read_dir {
#[call] #[call]
pub async extern "Lua-C" fn next(&mut self) -> Result<Option<lb_dirent>> { pub async extern "Lua-C" fn next(&mut self) -> Result<Option<lb_dir_entry>> {
Ok(self.0.next_entry().await?.map(Into::into)) Ok(self.0.next_entry().await?.map(Into::into))
} }
} }
/// Synchronous version of [`lb_lsdir`]. /// Synchronous version of [`lb_read_dir`].
#[derive(Debug, From)] #[derive(Debug, From)]
#[cdef] #[cdef]
pub struct lb_lsdir_sync(#[opaque] std::fs::ReadDir); pub struct lb_read_dir_sync(#[opaque] std::fs::ReadDir);
#[metatype] #[metatype]
impl lb_lsdir_sync { impl lb_read_dir_sync {
#[call] #[call]
pub extern "Lua-C" fn next(&mut self) -> Result<Option<lb_dirent_sync>> { pub extern "Lua-C" fn next(&mut self) -> Result<Option<lb_dir_entry_sync>> {
Ok(self.0.next().transpose()?.map(Into::into)) Ok(self.0.next().transpose()?.map(Into::into))
} }
} }
@ -101,10 +101,10 @@ impl lb_lsdir_sync {
/// Entry inside of a directory on the filesystem. /// Entry inside of a directory on the filesystem.
#[derive(Debug, From)] #[derive(Debug, From)]
#[cdef] #[cdef]
pub struct lb_dirent(#[opaque] tokio::fs::DirEntry); pub struct lb_dir_entry(#[opaque] tokio::fs::DirEntry);
#[metatype] #[metatype]
impl lb_dirent { impl lb_dir_entry {
pub extern "Lua-C" fn path(&self) -> String { pub extern "Lua-C" fn path(&self) -> String {
self.0.path().to_string_lossy().into() self.0.path().to_string_lossy().into()
} }
@ -132,13 +132,13 @@ impl lb_dirent {
} }
} }
/// Synchronous version of [`lb_dirent`]. /// Synchronous version of [`lb_dir_entry`].
#[derive(Debug, From)] #[derive(Debug, From)]
#[cdef] #[cdef]
pub struct lb_dirent_sync(#[opaque] std::fs::DirEntry); pub struct lb_dir_entry_sync(#[opaque] std::fs::DirEntry);
#[metatype] #[metatype]
impl lb_dirent_sync { impl lb_dir_entry_sync {
pub extern "Lua-C" fn path(&self) -> String { pub extern "Lua-C" fn path(&self) -> String {
self.0.path().to_string_lossy().into() self.0.path().to_string_lossy().into()
} }
@ -167,7 +167,7 @@ impl lb_dirent_sync {
} }
} }
/// Structure representing a type of file with accessors for each file type. /// Structure representing the type of a file with accessors for each file type.
#[derive(Debug, From)] #[derive(Debug, From)]
#[cdef] #[cdef]
pub struct lb_file_type(#[opaque] std::fs::FileType); pub struct lb_file_type(#[opaque] std::fs::FileType);