diff options
Diffstat (limited to 'src/rt')
| -rw-r--r-- | src/rt/rust_builtin.cpp | 18 | ||||
| -rw-r--r-- | src/rt/rustrt.def.in | 1 |
2 files changed, 19 insertions, 0 deletions
diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 297b9df7..bc2c5add 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -226,6 +226,24 @@ str_push_byte(rust_task* task, rust_str* v, size_t byte) return v; } +extern "C" CDECL rust_str* +str_slice(rust_task* task, rust_str* v, size_t begin, size_t end) +{ + size_t len = end - begin; + rust_str *st = + vec_alloc_with_data(task, + len + 1, // +1 to fit at least '\0' + len, + 1, + len ? v->data + begin : NULL); + if (!st) { + task->fail(2); + return NULL; + } + st->data[st->fill++] = '\0'; + return st; +} + extern "C" CDECL char const * str_buf(rust_task *task, rust_str *s) { diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in index b2d42463..1258f97b 100644 --- a/src/rt/rustrt.def.in +++ b/src/rt/rustrt.def.in @@ -32,6 +32,7 @@ str_from_buf str_from_cstr str_from_vec str_push_byte +str_slice str_vec task_sleep unsafe_vec_to_mut |