mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 08:34:33 +00:00
Add effects for file I/O
This commit is contained in:
parent
f3dfab8a94
commit
963acb0ff5
1 changed files with 22 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue