1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

all: basic implementation of result type (#14140)

This commit is contained in:
Daniel Däschle
2022-04-30 00:59:14 +02:00
committed by GitHub
parent db185e6580
commit 08fd0ce0de
39 changed files with 478 additions and 79 deletions

View File

@@ -118,6 +118,22 @@ fn opt_ok(data voidptr, mut option Option, size int) {
}
}
struct result {
is_error bool
err IError = none__
// Data is trailing after err
// and is not included in here but in the
// derived Result_xxx types
}
fn result_ok(data voidptr, mut res result, size int) {
unsafe {
*res = result{}
// use err to get the end of ResultBase and then memcpy into it
vmemcpy(&u8(&res.err) + sizeof(IError), data, size)
}
}
pub fn (_ none) str() string {
return 'none'
}