Skip to content

Commit fb1b204

Browse files
committed
fix type incompatibilities from unsupported re-exports
1 parent 9f67126 commit fb1b204

File tree

3 files changed

+76
-13
lines changed

3 files changed

+76
-13
lines changed

library/std/src/sys/fs/vexos.rs

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ use crate::sys::{unsupported, unsupported_err};
1111
#[expect(dead_code)]
1212
#[path = "unsupported.rs"]
1313
mod unsupported_fs;
14-
1514
pub use unsupported_fs::{
16-
DirBuilder, FilePermissions, FileTimes, ReadDir, canonicalize, link, remove_dir_all, rename,
17-
rmdir, set_perm, symlink, unlink,
15+
DirBuilder, FileTimes, canonicalize, link, readlink, remove_dir_all, rename, rmdir, symlink,
16+
unlink,
1817
};
1918

2019
#[derive(Debug)]
@@ -30,6 +29,8 @@ pub enum FileAttr {
3029
File { size: u64 },
3130
}
3231

32+
pub struct ReadDir(!);
33+
3334
pub struct DirEntry {
3435
path: PathBuf,
3536
}
@@ -44,6 +45,9 @@ pub struct OpenOptions {
4445
create_new: bool,
4546
}
4647

48+
#[derive(Clone, PartialEq, Eq, Debug)]
49+
pub struct FilePermissions {}
50+
4751
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
4852
pub struct FileType {
4953
is_dir: bool,
@@ -108,6 +112,16 @@ impl FileAttr {
108112
}
109113
}
110114

115+
impl FilePermissions {
116+
pub fn readonly(&self) -> bool {
117+
false
118+
}
119+
120+
pub fn set_readonly(&mut self, _readonly: bool) {
121+
panic!("Perimissions do not exist")
122+
}
123+
}
124+
111125
impl FileType {
112126
pub fn is_dir(&self) -> bool {
113127
self.is_dir
@@ -123,6 +137,38 @@ impl FileType {
123137
}
124138
}
125139

140+
impl fmt::Debug for ReadDir {
141+
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
142+
self.0
143+
}
144+
}
145+
146+
impl Iterator for ReadDir {
147+
type Item = io::Result<DirEntry>;
148+
149+
fn next(&mut self) -> Option<io::Result<DirEntry>> {
150+
self.0
151+
}
152+
}
153+
154+
impl DirEntry {
155+
pub fn path(&self) -> PathBuf {
156+
self.path.clone()
157+
}
158+
159+
pub fn file_name(&self) -> OsString {
160+
self.path.file_name().unwrap_or_default().into()
161+
}
162+
163+
pub fn metadata(&self) -> io::Result<FileAttr> {
164+
stat(&self.path)
165+
}
166+
167+
pub fn file_type(&self) -> io::Result<FileType> {
168+
Ok(self.metadata()?.file_type())
169+
}
170+
}
171+
126172
impl OpenOptions {
127173
pub fn new() -> OpenOptions {
128174
OpenOptions {
@@ -436,6 +482,21 @@ impl Drop for File {
436482
}
437483
}
438484

485+
pub fn readdir(_p: &Path) -> io::Result<ReadDir> {
486+
// While there *is* a userspace function for reading file directories,
487+
// the necessary implementation cannot currently be done cleanly, as
488+
// VEXos does not expose directory length to user programs.
489+
//
490+
// This means that we would need to create a large fixed-length buffer
491+
// and hope that the folder's contents didn't exceed that buffer's length,
492+
// which obviously isn't behavior we want to rely on in the standard library.
493+
unsupported()
494+
}
495+
496+
pub fn set_perm(_p: &Path, _perm: FilePermissions) -> io::Result<()> {
497+
unsupported()
498+
}
499+
439500
pub fn exists(path: &Path) -> io::Result<bool> {
440501
run_path_with_cstr(path, &|path| Ok(unsafe { vex_sdk::vexFileStatus(path.as_ptr()) } != 0))
441502
}

library/std/src/sys/pal/vexos/thread.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
#[expect(dead_code)]
2-
#[path = "unsupported.rs"]
3-
mod unsupported_thread;
4-
5-
pub use unsupported_thread::{DEFAULT_MIN_STACK_SIZE, available_parallelism, current_os_id};
6-
71
use super::unsupported;
82
use crate::ffi::CStr;
93
use crate::io;
104
use crate::num::NonZero;
115
use crate::time::{Duration, Instant};
126

7+
#[expect(dead_code)]
8+
#[path = "../unsupported/thread.rs"]
9+
mod unsupported_thread;
10+
pub use unsupported_thread::{DEFAULT_MIN_STACK_SIZE, available_parallelism};
11+
1312
pub struct Thread(!);
1413

1514
impl Thread {
@@ -54,3 +53,7 @@ impl Thread {
5453
self.0
5554
}
5655
}
56+
57+
pub(crate) fn current_os_id() -> Option<u64> {
58+
None
59+
}

library/std/src/sys/pal/vexos/time.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1+
use crate::time::Duration;
2+
13
#[expect(dead_code)]
2-
#[path = "unsupported.rs"]
4+
#[path = "../unsupported/time.rs"]
35
mod unsupported_time;
4-
56
pub use unsupported_time::{SystemTime, UNIX_EPOCH};
67

7-
use crate::time::Duration;
8-
98
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
109
pub struct Instant(Duration);
1110

0 commit comments

Comments
 (0)