summaryrefslogtreecommitdiffhomepage
path: root/src/kernel/NeKit/ErrorOr.h
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-12-11 08:34:36 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2025-12-11 08:34:36 +0100
commitfe58b444de6c00089010d308a39f78890b1782b6 (patch)
tree84849ef1576aca5410210503c58268d3a9592c14 /src/kernel/NeKit/ErrorOr.h
parent076c8378e96a9fac9864c9d02bb63fa7dd423e4a (diff)
feat: kernel: `Vettable.h` interface and concepts.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'src/kernel/NeKit/ErrorOr.h')
-rw-r--r--src/kernel/NeKit/ErrorOr.h23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/kernel/NeKit/ErrorOr.h b/src/kernel/NeKit/ErrorOr.h
index 7de7434d..d9fc972d 100644
--- a/src/kernel/NeKit/ErrorOr.h
+++ b/src/kernel/NeKit/ErrorOr.h
@@ -25,33 +25,36 @@ class ErrorOr final {
~ErrorOr() = default;
public:
+ using RefType = Ref<T>;
+ using Type = T;
+
explicit ErrorOr(ErrorT err) : mRef((T*) RTL_ALLOCA(sizeof(T))), mId(err) {}
explicit ErrorOr(nullPtr) {}
- explicit ErrorOr(T* klass) : mRef(klass) {}
- explicit ErrorOr(T klass) : mRef(klass) {}
+ explicit ErrorOr(Type* klass) : mRef(klass) {}
+ explicit ErrorOr(Type klass) : mRef(klass) {}
ErrorOr& operator=(const ErrorOr&) = default;
ErrorOr(const ErrorOr&) = default;
- ErrorOr& operator=(const Ref<T>& refErr) {
- mRef = refErr;
+ ErrorOr& operator=(const RefType& ref) {
+ mRef = ref;
return *this;
}
- const T& Value() { return mRef.TryLeak(); }
+ const Type& Value() { return mRef.TryLeak(); }
- Ref<T>& Leak() { return mRef; }
+ RefType& Leak() { return mRef; }
ErrorT Error() { return mId; }
/// @note DO NOT MAKE THIS EXPLICIT! IT WILL BREAK THE COMPILATION.
- operator bool() { return mRef; }
+ explicit operator bool() { return mRef.Leak(); }
- BOOL HasError() { return this->mId < 0; }
+ BOOL HasError() { return this->mId < kErrorSuccess; }
private:
- Ref<T> mRef;
- ErrorT mId{0};
+ RefType mRef;
+ ErrorT mId{0};
};
using ErrorOrAny = ErrorOr<voidPtr>;