Skip to content

Commit 98ea463

Browse files
committed
re-export relevant items from unsupported in vexos modules
1 parent 081593b commit 98ea463

File tree

3 files changed

+21
-155
lines changed

3 files changed

+21
-155
lines changed

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

Lines changed: 9 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ use crate::sys::common::small_c_string::run_path_with_cstr;
88
use crate::sys::time::SystemTime;
99
use crate::sys::{unsupported, unsupported_err};
1010

11+
#[expect(dead_code)]
12+
#[path = "unsupported.rs"]
13+
mod unsupported_fs;
14+
15+
pub use unsupported_fs::{
16+
DirBuilder, FilePermissions, FileTimes, ReadDir, canonicalize, link, remove_dir_all, rename,
17+
rmdir, set_perm, symlink, unlink,
18+
};
19+
1120
#[derive(Debug)]
1221
struct FileDesc(*mut vex_sdk::FIL);
1322

@@ -21,8 +30,6 @@ pub enum FileAttr {
2130
File { size: u64 },
2231
}
2332

24-
pub struct ReadDir(!);
25-
2633
pub struct DirEntry {
2734
path: PathBuf,
2835
}
@@ -37,20 +44,11 @@ pub struct OpenOptions {
3744
create_new: bool,
3845
}
3946

40-
#[derive(Copy, Clone, Debug, Default)]
41-
pub struct FileTimes {}
42-
43-
#[derive(Clone, PartialEq, Eq, Debug)]
44-
pub struct FilePermissions {}
45-
4647
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
4748
pub struct FileType {
4849
is_dir: bool,
4950
}
5051

51-
#[derive(Debug)]
52-
pub struct DirBuilder {}
53-
5452
impl FileAttr {
5553
/// Creates a FileAttr by getting data from an opened file.
5654
fn from_fd(fd: *mut vex_sdk::FIL) -> io::Result<Self> {
@@ -110,21 +108,6 @@ impl FileAttr {
110108
}
111109
}
112110

113-
impl FilePermissions {
114-
pub fn readonly(&self) -> bool {
115-
false
116-
}
117-
118-
pub fn set_readonly(&mut self, _readonly: bool) {
119-
panic!("Perimissions do not exist")
120-
}
121-
}
122-
123-
impl FileTimes {
124-
pub fn set_accessed(&mut self, _t: SystemTime) {}
125-
pub fn set_modified(&mut self, _t: SystemTime) {}
126-
}
127-
128111
impl FileType {
129112
pub fn is_dir(&self) -> bool {
130113
self.is_dir
@@ -140,38 +123,6 @@ impl FileType {
140123
}
141124
}
142125

143-
impl fmt::Debug for ReadDir {
144-
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
145-
self.0
146-
}
147-
}
148-
149-
impl Iterator for ReadDir {
150-
type Item = io::Result<DirEntry>;
151-
152-
fn next(&mut self) -> Option<io::Result<DirEntry>> {
153-
self.0
154-
}
155-
}
156-
157-
impl DirEntry {
158-
pub fn path(&self) -> PathBuf {
159-
self.path.clone()
160-
}
161-
162-
pub fn file_name(&self) -> OsString {
163-
self.path.file_name().unwrap_or_default().into()
164-
}
165-
166-
pub fn metadata(&self) -> io::Result<FileAttr> {
167-
stat(&self.path)
168-
}
169-
170-
pub fn file_type(&self) -> io::Result<FileType> {
171-
Ok(self.metadata()?.file_type())
172-
}
173-
}
174-
175126
impl OpenOptions {
176127
pub fn new() -> OpenOptions {
177128
OpenOptions {
@@ -474,16 +425,6 @@ impl File {
474425
}
475426
}
476427

477-
impl DirBuilder {
478-
pub fn new() -> DirBuilder {
479-
DirBuilder {}
480-
}
481-
482-
pub fn mkdir(&self, _p: &Path) -> io::Result<()> {
483-
unsupported()
484-
}
485-
}
486-
487428
impl fmt::Debug for File {
488429
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
489430
f.debug_struct("File").field("fd", &self.fd.0).finish()
@@ -495,53 +436,10 @@ impl Drop for File {
495436
}
496437
}
497438

498-
pub fn readdir(_p: &Path) -> io::Result<ReadDir> {
499-
// While there *is* a userspace function for reading file directories,
500-
// the necessary implementation cannot currently be done cleanly, as
501-
// VEXos does not expose directory length to user programs.
502-
//
503-
// This means that we would need to create a large fixed-length buffer
504-
// and hope that the folder's contents didn't exceed that buffer's length,
505-
// which obviously isn't behavior we want to rely on in the standard library.
506-
unsupported()
507-
}
508-
509-
pub fn unlink(_p: &Path) -> io::Result<()> {
510-
unsupported()
511-
}
512-
513-
pub fn rename(_old: &Path, _new: &Path) -> io::Result<()> {
514-
unsupported()
515-
}
516-
517-
pub fn set_perm(_p: &Path, _perm: FilePermissions) -> io::Result<()> {
518-
unsupported()
519-
}
520-
521-
pub fn rmdir(_p: &Path) -> io::Result<()> {
522-
unsupported()
523-
}
524-
525-
pub fn remove_dir_all(_path: &Path) -> io::Result<()> {
526-
unsupported()
527-
}
528-
529439
pub fn exists(path: &Path) -> io::Result<bool> {
530440
run_path_with_cstr(path, &|path| Ok(unsafe { vex_sdk::vexFileStatus(path.as_ptr()) } != 0))
531441
}
532442

533-
pub fn readlink(_p: &Path) -> io::Result<PathBuf> {
534-
unsupported()
535-
}
536-
537-
pub fn symlink(_original: &Path, _link: &Path) -> io::Result<()> {
538-
unsupported()
539-
}
540-
541-
pub fn link(_src: &Path, _dst: &Path) -> io::Result<()> {
542-
unsupported()
543-
}
544-
545443
pub fn stat(p: &Path) -> io::Result<FileAttr> {
546444
FileAttr::from_path(p)
547445
}
@@ -551,10 +449,6 @@ pub fn lstat(p: &Path) -> io::Result<FileAttr> {
551449
stat(p)
552450
}
553451

554-
pub fn canonicalize(_p: &Path) -> io::Result<PathBuf> {
555-
unsupported()
556-
}
557-
558452
pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
559453
use crate::fs::File;
560454

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
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+
17
use super::unsupported;
28
use crate::ffi::CStr;
39
use crate::io;
410
use crate::num::NonZero;
511
use crate::time::{Duration, Instant};
612

7-
pub const DEFAULT_MIN_STACK_SIZE: usize = 64 * 1024;
8-
913
pub struct Thread(!);
1014

1115
impl Thread {
@@ -50,11 +54,3 @@ impl Thread {
5054
self.0
5155
}
5256
}
53-
54-
pub(crate) fn current_os_id() -> Option<u64> {
55-
None
56-
}
57-
58-
pub fn available_parallelism() -> io::Result<NonZero<usize>> {
59-
unsupported()
60-
}

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

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
#[expect(dead_code)]
2+
#[path = "unsupported.rs"]
3+
mod unsupported_time;
4+
5+
pub use unsupported_time::{SystemTime, UNIX_EPOCH};
6+
17
use crate::time::Duration;
28

39
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
410
pub struct Instant(Duration);
511

6-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
7-
pub struct SystemTime(Duration);
8-
9-
pub const UNIX_EPOCH: SystemTime = SystemTime(Duration::from_secs(0));
10-
1112
impl Instant {
1213
pub fn now() -> Instant {
1314
let micros = unsafe { vex_sdk::vexSystemHighResTimeGet() };
@@ -26,28 +27,3 @@ impl Instant {
2627
Some(Instant(self.0.checked_sub(*other)?))
2728
}
2829
}
29-
30-
impl SystemTime {
31-
pub fn now() -> SystemTime {
32-
panic!("system time not implemented on this platform")
33-
}
34-
35-
#[rustc_const_unstable(feature = "const_system_time", issue = "144517")]
36-
pub const fn sub_time(&self, other: &SystemTime) -> Result<Duration, Duration> {
37-
// FIXME: ok_or_else with const closures
38-
match self.0.checked_sub(other.0) {
39-
Some(duration) => Ok(duration),
40-
None => Err(other.0 - self.0),
41-
}
42-
}
43-
44-
#[rustc_const_unstable(feature = "const_system_time", issue = "144517")]
45-
pub const fn checked_add_duration(&self, other: &Duration) -> Option<SystemTime> {
46-
Some(SystemTime(self.0.checked_add(*other)?))
47-
}
48-
49-
#[rustc_const_unstable(feature = "const_system_time", issue = "144517")]
50-
pub const fn checked_sub_duration(&self, other: &Duration) -> Option<SystemTime> {
51-
Some(SystemTime(self.0.checked_sub(*other)?))
52-
}
53-
}

0 commit comments

Comments
 (0)