mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +00:00
Extract write_slice
This commit is contained in:
parent
ca730c5b52
commit
13ae5c068b
1 changed files with 11 additions and 19 deletions
|
@ -150,33 +150,25 @@ pub enum WriteErr {
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn roc_fx_fileWriteUtf8(
|
pub extern "C" fn roc_fx_fileWriteUtf8(
|
||||||
path: &RocList<u8>,
|
roc_path: &RocList<u8>,
|
||||||
string: &RocStr,
|
roc_string: &RocStr,
|
||||||
) -> RocResult<(), WriteErr> {
|
) -> RocResult<(), WriteErr> {
|
||||||
use std::io::Write;
|
write_slice(roc_path, roc_string.as_str().as_bytes())
|
||||||
|
|
||||||
match File::create(path_from_list(path)) {
|
|
||||||
Ok(mut file) => match file.write_all(string.as_str().as_bytes()) {
|
|
||||||
Ok(()) => RocResult::ok(()),
|
|
||||||
Err(_) => {
|
|
||||||
todo!("Report a file write error");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Err(_) => {
|
|
||||||
todo!("Report a file open error");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn roc_fx_fileWriteBytes(
|
pub extern "C" fn roc_fx_fileWriteBytes(
|
||||||
path: &RocList<u8>,
|
roc_path: &RocList<u8>,
|
||||||
bytes: &RocList<u8>,
|
roc_bytes: &RocList<u8>,
|
||||||
) -> RocResult<(), WriteErr> {
|
) -> RocResult<(), WriteErr> {
|
||||||
|
write_slice(roc_path, roc_bytes.as_slice())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_slice(roc_path: &RocList<u8>, bytes: &[u8]) -> RocResult<(), WriteErr> {
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
match File::create(path_from_list(path)) {
|
match File::create(path_from_list(roc_path)) {
|
||||||
Ok(mut file) => match file.write_all(bytes.as_slice()) {
|
Ok(mut file) => match file.write_all(bytes) {
|
||||||
Ok(()) => RocResult::ok(()),
|
Ok(()) => RocResult::ok(()),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
todo!("Report a file write error");
|
todo!("Report a file write error");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue