-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement listing directories in Inko
std::fs::dir.list is now located at std::fs::path::Path.list, and is implemented entirely using Inko, instead of relying on runtime library functions. This requires some OS specific bits, but helps us decouple Inko more from Rust, and avoids the need for heap allocating Rust structures just to work around its lack of a stable ABI. As part of these changes, the return type is also changed: instead of returning Array[Path], Path.list returns in iterator that yields DirectoryEntry values, containing both a path and a file type. This commit also introduces the module std::fs, containing general file system types such as FileType and DirectoryEntry. This module is meant for types that aren't really "owned" by more specific modules, such as std::fs::path. The internal bits are currently marked as public in a few places, as we currently lack a notion of "namespace private" or "project private" types/methods, but this will probably change in the future. We also introduce some syntax and FFI changes: identifiers may now contain dollar signs, as AMD64 macOS code needs to use e.g. opendir$INODE64() instead of regular opendir(). The compiler code is tweaked here and there to correctly compile calls such as module.foo() where foo() is an external method, something that didn't work before. This fixes #517. Changelog: changed
- Loading branch information
1 parent
3e3da16
commit 0c963af
Showing
25 changed files
with
527 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# General types for filesystem operations. | ||
import std::cmp::Equal | ||
import std::fmt::(Format, Formatter) | ||
import std::fs::path::Path | ||
|
||
# A type describing the type of file, such as a file or directory. | ||
class pub enum FileType { | ||
# The file is a file. | ||
case File | ||
|
||
# The file is a directory. | ||
case Directory | ||
|
||
# The file is a symbolic link. | ||
case SymbolicLink | ||
|
||
# The file is something else that isn't explicitly covered by this type. | ||
case Other | ||
} | ||
|
||
impl Equal[FileType] for FileType { | ||
fn pub ==(other: ref FileType) -> Bool { | ||
match (self, other) { | ||
case (File, File) -> true | ||
case (Directory, Directory) -> true | ||
case (SymbolicLink, SymbolicLink) -> true | ||
case (Other, Other) -> true | ||
case _ -> false | ||
} | ||
} | ||
} | ||
|
||
impl Format for FileType { | ||
fn pub fmt(formatter: mut Formatter) { | ||
let write = match self { | ||
case File -> 'File' | ||
case Directory -> 'Directory' | ||
case SymbolicLink -> 'SymbolicLink' | ||
case Other -> 'Other' | ||
} | ||
|
||
formatter.write(write) | ||
} | ||
} | ||
|
||
# An entry in a directory. | ||
# | ||
# Instances of this type are typically produced by `std::fs::path::Path.list`, | ||
# so see that method's documentation for additional details. | ||
class pub DirectoryEntry { | ||
# The path to the entry. | ||
let pub @path: Path | ||
|
||
# The type of this entry. | ||
let pub @type: FileType | ||
} | ||
|
||
impl Equal[DirectoryEntry] for DirectoryEntry { | ||
fn pub ==(other: ref DirectoryEntry) -> Bool { | ||
@path == other.path and @type == other.type | ||
} | ||
} | ||
|
||
impl Format for DirectoryEntry { | ||
fn pub fmt(formatter: mut Formatter) { | ||
formatter.write('DirectoryEntry { ') | ||
|
||
formatter.descend fn { | ||
formatter.write('@path = ') | ||
@path.fmt(formatter) | ||
formatter.write(', @type = ') | ||
@type.fmt(formatter) | ||
} | ||
|
||
formatter.write(' }') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.