Skip to content

Commit 05f27df

Browse files
committed
Use new path type from neotron-api.
1 parent f640a6e commit 05f27df

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

src/lib.rs

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ use core::sync::atomic::{AtomicPtr, Ordering};
1212

1313
pub use neotron_ffi::{FfiBuffer, FfiByteSlice, FfiString};
1414

15-
pub use neotron_api::{dir, file, Api, Error};
15+
pub use neotron_api::{path, Api, Error};
16+
17+
use neotron_api as api;
1618

1719
// ============================================================================
1820
// Constants
@@ -58,7 +60,7 @@ pub type AppStartFn = extern "C" fn(*mut crate::Api) -> i32;
5860
pub type Result<T> = core::result::Result<T, Error>;
5961

6062
/// Represents an open File
61-
pub struct File(file::Handle);
63+
pub struct File(api::file::Handle);
6264

6365
impl File {
6466
/// Open a file, given a path as UTF-8 string.
@@ -73,9 +75,9 @@ impl File {
7375
/// * You cannot open a file if it is currently open.
7476
/// * Paths must confirm to the rules for the filesystem for the given drive.
7577
/// * Relative paths are taken relative to the current directory (see `Api::chdir`).
76-
pub fn open(path: file::Path, flags: file::Flags) -> Result<Self> {
78+
pub fn open(path: path::Path, flags: api::file::Flags) -> Result<Self> {
7779
let api = get_api();
78-
match (api.open)(path, flags) {
80+
match (api.open)(FfiString::new(path.as_str()), flags) {
7981
neotron_ffi::FfiResult::Ok(handle) => Ok(File(handle)),
8082
neotron_ffi::FfiResult::Err(e) => Err(e),
8183
}
@@ -166,9 +168,12 @@ impl File {
166168
/// * You cannot rename a file where the `old_path` and the `new_path` are
167169
/// not on the same drive.
168170
/// * Paths must confirm to the rules for the filesystem for the given drive.
169-
pub fn rename(old_path: file::Path, new_path: file::Path) -> Result<()> {
171+
pub fn rename(old_path: path::Path, new_path: path::Path) -> Result<()> {
170172
let api = get_api();
171-
match (api.rename)(old_path, new_path) {
173+
match (api.rename)(
174+
FfiString::new(old_path.as_str()),
175+
FfiString::new(new_path.as_str()),
176+
) {
172177
neotron_ffi::FfiResult::Ok(_) => Ok(()),
173178
neotron_ffi::FfiResult::Err(e) => Err(e),
174179
}
@@ -186,7 +191,7 @@ impl File {
186191
}
187192

188193
/// Get information about this file.
189-
pub fn stat(&self) -> Result<file::Stat> {
194+
pub fn stat(&self) -> Result<api::file::Stat> {
190195
let api = get_api();
191196
match (api.fstat)(self.0) {
192197
neotron_ffi::FfiResult::Ok(output) => Ok(output),
@@ -205,20 +210,20 @@ impl core::ops::Drop for File {
205210
}
206211

207212
/// Represents an open directory that we are iterating through.
208-
pub struct ReadDir(dir::Handle);
213+
pub struct ReadDir(api::dir::Handle);
209214

210215
impl ReadDir {
211-
pub fn open(path: file::Path) -> Result<ReadDir> {
216+
pub fn open(path: path::Path) -> Result<ReadDir> {
212217
let api = get_api();
213-
match (api.opendir)(path) {
218+
match (api.opendir)(FfiString::new(path.as_str())) {
214219
neotron_ffi::FfiResult::Ok(output) => Ok(ReadDir(output)),
215220
neotron_ffi::FfiResult::Err(e) => Err(e),
216221
}
217222
}
218223
}
219224

220225
impl Iterator for ReadDir {
221-
type Item = Result<dir::Entry>;
226+
type Item = Result<api::dir::Entry>;
222227

223228
fn next(&mut self) -> Option<Self::Item> {
224229
None
@@ -246,30 +251,30 @@ extern "C" fn app_entry(api: *mut Api) -> i32 {
246251
}
247252

248253
/// Get information about a file on disk.
249-
pub fn stat(_path: file::Path) -> Result<file::Stat> {
254+
pub fn stat(_path: path::Path) -> Result<api::file::Stat> {
250255
todo!()
251256
}
252257

253258
/// Delete a file from disk
254-
pub fn delete(_path: file::Path) -> Result<()> {
259+
pub fn delete(_path: path::Path) -> Result<()> {
255260
todo!()
256261
}
257262

258263
/// Change the current working directory to the given path.
259-
pub fn chdir(_path: file::Path) -> Result<()> {
264+
pub fn chdir(_path: path::Path) -> Result<()> {
260265
todo!()
261266
}
262267

263268
/// Change the current working directory to that given by the handle.
264-
pub fn dchdir(_dir: dir::Handle) -> Result<()> {
269+
pub fn dchdir(_dir: api::dir::Handle) -> Result<()> {
265270
todo!()
266271
}
267272

268273
/// Get the current working directory.
269274
///
270275
/// Provided as a call-back, so the caller doesn't need to allocate storage space for the string.
271-
pub fn pwd<F: FnOnce(Result<file::Path>)>(callback: F) {
272-
callback(Err(Error::FileNotFound))
276+
pub fn pwd<F: FnOnce(Result<path::Path>)>(callback: F) {
277+
callback(Err(Error::NotFound))
273278
}
274279

275280
/// Alllocate some memory
@@ -284,17 +289,17 @@ pub fn free(_ptr: *mut core::ffi::c_void, _size: usize, _alignment: usize) {
284289

285290
/// Get a handle for Standard Input
286291
pub fn stdin() -> File {
287-
File(file::Handle::new_stdin())
292+
File(api::file::Handle::new_stdin())
288293
}
289294

290295
/// Get a handle for Standard Output
291296
pub fn stdout() -> File {
292-
File(file::Handle::new_stdout())
297+
File(api::file::Handle::new_stdout())
293298
}
294299

295300
/// Get a handle for Standard Error
296301
pub fn stderr() -> File {
297-
File(file::Handle::new_stderr())
302+
File(api::file::Handle::new_stderr())
298303
}
299304

300305
/// Get the API structure so we can call APIs manually.

0 commit comments

Comments
 (0)