24 lines
589 B
C
24 lines
589 B
C
#include "pureoption.h"
|
|
#include <stddef.h>
|
|
|
|
inline static pureoption __pureoption_new(bool has_value, void *value) {
|
|
pureoption result = {
|
|
.has_value = has_value,
|
|
.value = value,
|
|
};
|
|
|
|
return result;
|
|
}
|
|
|
|
pureoption _pureoption_some(void *value) {
|
|
return __pureoption_new(true, value);
|
|
}
|
|
|
|
pureoption pureoption_none(void) { return __pureoption_new(false, NULL); }
|
|
|
|
bool pureoption_has(pureoption option) { return option.has_value; }
|
|
|
|
bool pureoption_lacks(pureoption option) { return !option.has_value; }
|
|
|
|
void *_pureoption_get(pureoption option) { return option.value; }
|