Crate rivia

source · []
Expand description

Provides a unified, simplified systems api including essential macros and extensions to fill in gaps in Rust ergonomics and reduce the amount of boiler plate code required for common tasks. The intent is to provide this while keeping dependencies to a minimum.

Virtual FileSystem (VFS)

Switching out VFS backends

Using the power of Rust enums we can create a simple virtual file system with multiple backend implementations that can easily be switched out at compile time for testing purposes with almost zero additional overhead by simply passing in a vfs reference to functions needing to manipulate the filesystem. For those wishing for a truely seamless experience see the rivia-vfs crate for a global singleton that can be dynamically updated at runtime thus avoiding passing a vfs reference around.

use rivia::prelude::*;

fn switching_vfs_backends((vfs, tmpdir): (Vfs, PathBuf))
{
    let dir = tmpdir.mash("dir");
    let file = dir.mash("file");
    assert_vfs_mkdir_p!(&vfs, &dir);
    assert_vfs_mkfile!(&vfs, &file);
    assert_vfs_remove!(&vfs, &file);
    assert_vfs_remove_all!(&vfs, &tmpdir);
}

switching_vfs_backends(assert_vfs_setup!(Vfs::memfs()));
switching_vfs_backends(assert_vfs_setup!(Vfs::stdfs()));

Rejected Considerations

VfsPath

VfsPath was considered as a way to track and not repeat environment variable and absolute path resolution. Additionally it would be used in the VFS case to track the VFS backend being used to allow for extensions to a Path to chain call additional operations. However the relative amount of overhead of resolving paths is small when compared to disk IO which will usually be being done. What’s more the benefit of trackig the VFS for chain calling is dubious when you introduce the complexity of multiple ways to get access to VFS operations. Considering the ergonomic impact and commplexity of such a change. I won’t be implementing a notion of a VfsPath in favor of a single point of entry into the VFS operations and much cleaner ergonomics i.e. always use the Filesystem backend trait implementation via Vfs for every Filesystem related operation.

Using Rivia

use rivia::prelude::*;

Modules

Provides general extensions to common types like Option, Result and Iterator.

Provides a common set of errors across the rivia crates to reduce the verbosity of error handling

All essential symbols in a simple consumable way

Provides a unified, simplified systems api

Provides a set of testing functions and macros to reduce testing boiler plate

Macros

Assert the copy of a file

Assert that a file or directory exists

Assert that the given path exists and is a directory

Assert that the given path exists and is a file

Assert that the given path exists and is a symlink

Assert the creation of the given directory with the given mode

Assert the creation of the given directory.

Assert the creation of a file. If the file exists no change is made

Assert that the given path isn’t a directory

Assert the given path doesn’t exist

Assert that the given path isn’t a file

Assert that the given path isn’t a symlink

Assert data read from the file matches the input data

Assert the reading of a link’s target relative path

Assert the reading of a link’s target absolute path

Assert the removal of the target file or directory

Assert the removal of the target path

Setup Vfs testing components

Assert the creation of a symlink. If the symlink exists no change is made

Assert data is written to the given file

Provides the ability to define #[cfg] statements for multiple items

Ensure the given closure is executed once the surrounding scope closes

Expands to the current function’s name similar to the venerable file! or line!

Expands to the current functions’s fully qualified name

Helper function for testing to simply panic with the given message in a repeatable formatting.

Helper function for testing to simply panic with the given message in a repeatable formatting.

Return an iterator Err type conveniently

Unwrap the value on Ok or return false on Err