Code Monkey home page Code Monkey logo

Comments (6)

gahag avatar gahag commented on August 15, 2024 1

Surely, a full featured io/fs library is a must. Your PR would be more than welcome! Please let me know if I can be of any help.

from hush.

gahag avatar gahag commented on August 15, 2024 1

For a 100% feature complete set, I'd consider Rust's own std::fs module:

  • canonicalize: Returns the canonical, absolute form of a path with all intermediate components normalized and symbolic links resolved.
  • copy: Copies the contents of one file to another. This function will also copy the permission bits of the original file to the destination file.
  • create_dir: Creates a new, empty directory at the provided path
  • create_dir_all: Recursively create a directory and all of its parent components if they are missing.
  • hard_link: Creates a new hard link on the filesystem.
  • metadata: Given a path, query the file system to get information about a file, directory, etc.
  • read: Read the entire contents of a file into a bytes vector.
  • read_dir: Returns an iterator over the entries within a directory.
  • read_link: Reads a symbolic link, returning the file that the link points to.
  • read_to_string: Read the entire contents of a file into a string.
  • remove_dir: Removes an empty directory.
  • remove_dir_all: Removes a directory at this path, after removing all its contents. Use carefully!
  • remove_file: Removes a file from the filesystem.
  • rename: Rename a file or directory to a new name, replacing the original file if to already exists.
  • set_permissions: Changes the permissions found on a file or a directory.
  • soft_linkDeprecated: Creates a new symbolic link on the filesystem.
  • symlink_metadata: Query the metadata about a file without following symlinks.
  • write: Write a slice as the entire contents of a file

from hush.

deaddog avatar deaddog commented on August 15, 2024

I was mainly focused on the features I'm missing from bash. I have implementations for std.io.file_exists(...) and std.io.dir_exists(...) but I'd be up for adding some additional functions.

Do you have some suggestions for what those could be?

For most other fs operations I'd probably just rely on existing commands and the flexibility they already offer through various arguments. They're not too weird to use either:

# read a file
let mydata = ${ cat "/myfile" }.stdout
# delete a file
{ rm "/myfile" }
# write a file
{ echo "$mydata" > "/myfile" }

On the other hand this marks my first bit of Rust - I'd be up for a challenge.

from hush.

gahag avatar gahag commented on August 15, 2024

Makes sense, I believe I would use the existing commands in most cases too. It would be nice to have the basic functionality in the standard library tho, just in case. Feel free to implement whichever methods you'd like. And by the way, congrats for your first bit of Rust 🦀

from hush.

deaddog avatar deaddog commented on August 15, 2024

Fair point - some essential functions would be nice to have. I've listed the ones I could think of. Is there anything I've missed?

from hush.

gahag avatar gahag commented on August 15, 2024

Some of these would be collapsed into a single function, such as create_dir and create_dir_all, also read and read_to_string.

from hush.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.