ferrijs-std 0.2.1

Node and web standard library for the ferrijs QuickJS runtime: WHATWG Streams, Events, AbortController, Buffer, crypto, fs, os, url, zlib and the capability model they enforce (partly derived from awslabs/llrt, Apache-2.0).
Documentation
use crate::utils::result::ResultExt;
use rquickjs::{Ctx, Result};

pub(crate) fn rename_error(from: &str, to: &str) -> String {
    [
        "Can't rename file/folder from \"",
        from,
        "\" to \"",
        to,
        "\"",
    ]
    .concat()
}

pub async fn rename(ctx: Ctx<'_>, old_path: String, new_path: String) -> Result<()> {
    tokio::fs::rename(&old_path, &new_path)
        .await
        .or_throw_msg(&ctx, &rename_error(&old_path, &new_path))?;
    Ok(())
}

pub fn rename_sync(ctx: Ctx<'_>, old_path: String, new_path: String) -> Result<()> {
    std::fs::rename(&old_path, &new_path)
        .or_throw_msg(&ctx, &rename_error(&old_path, &new_path))?;
    Ok(())
}