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:
@@ -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'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user