MCPcopy Index your code
hub / github.com/RustPython/RustPython / next

Method next

crates/vm/src/stdlib/os.rs:960–1027  ·  view source on GitHub ↗
(zelf: &crate::Py<Self>, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

958 impl SelfIter for ScandirIterator {}
959 impl IterNext for ScandirIterator {
960 fn next(zelf: &crate::Py<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
961 let entryref: &mut Option<fs::ReadDir> = &mut zelf.entries.write();
962
963 match entryref {
964 None => Ok(PyIterReturn::StopIteration(None)),
965 Some(inner) => match inner.next() {
966 Some(entry) => match entry {
967 Ok(entry) => {
968 #[cfg(unix)]
969 let ino = {
970 use std::os::unix::fs::DirEntryExt;
971 entry.ino()
972 };
973 // TODO: wasi is nightly
974 // #[cfg(target_os = "wasi")]
975 // let ino = {
976 // use std::os::wasi::fs::DirEntryExt;
977 // entry.ino()
978 // };
979 #[cfg(not(unix))]
980 let ino = None;
981
982 let pathval = entry.path();
983
984 // On Windows, pre-cache lstat from directory entry metadata
985 // This allows stat() to return cached data even if file is removed
986 #[cfg(windows)]
987 let lstat = {
988 let cell = OnceCell::new();
989 if let Ok(stat_struct) =
990 crate::windows::win32_xstat(pathval.as_os_str(), false)
991 {
992 let stat_obj =
993 StatResultData::from_stat(&stat_struct, vm).to_pyobject(vm);
994 let _ = cell.set(stat_obj);
995 }
996 cell
997 };
998 #[cfg(not(windows))]
999 let lstat = OnceCell::new();
1000
1001 Ok(PyIterReturn::Return(
1002 DirEntry {
1003 file_name: entry.file_name(),
1004 pathval,
1005 file_type: entry.file_type(),
1006 #[cfg(unix)]
1007 d_type: None,
1008 #[cfg(not(any(windows, target_os = "redox")))]
1009 dir_fd: None,
1010 mode: zelf.mode,
1011 lstat,
1012 stat: OnceCell::new(),
1013 ino: AtomicCell::new(ino),
1014 }
1015 .into_ref(&vm.ctx)
1016 .into(),
1017 ))

Callers 15

compute_abstract_methodsFunction · 0.45
detect_source_encodingFunction · 0.45
min_or_maxFunction · 0.45
nextFunction · 0.45
parse_func_typeFunction · 0.45
reduceFunction · 0.45
py_newMethod · 0.45
callMethod · 0.45
start_joinable_threadFunction · 0.45
string_literal_to_objectFunction · 0.45
into_exprMethod · 0.45

Calls 15

newFunction · 0.85
win32_xstatFunction · 0.85
as_os_strMethod · 0.80
to_bytesMethod · 0.80
ErrClass · 0.50
SomeClass · 0.50
writeMethod · 0.45
pathMethod · 0.45
to_pyobjectMethod · 0.45
setMethod · 0.45
into_refMethod · 0.45
into_pyexceptionMethod · 0.45

Tested by

no test coverage detected