Add effects for file I/O

This commit is contained in:
Richard Feldman 2022-07-21 10:27:27 -04:00 committed by Ayaz Hafiz
parent f3dfab8a94
commit 963acb0ff5
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58

View file

@ -391,3 +391,25 @@ pub extern "C" fn roc_fx_envVarUtf8(key: &RocStr) -> RocStr {
RocStr::from(val.as_str())
}
#[no_mangle]
pub extern "C" fn roc_fx_writeUtf8(path: &RocStr, string: &RocStr) {
write_bytes(path, string.as_str().as_bytes())
}
#[no_mangle]
pub extern "C" fn roc_fx_writeBytes(path: &RocStr, bytes: &RocList<u8>) {
write_bytes(path, bytes.as_slice())
}
fn write_bytes(path: &RocStr, bytes: &[u8]) {
// TODO return Result
let mut file = File::create(path.as_str()).unwrap();
file.write_all(bytes).unwrap();
}
#[no_mangle]
pub extern "C" fn roc_fx_errLine(line: &RocStr) {
let string = line.as_str();
eprintln!("{}", string);
}