summaryrefslogtreecommitdiffhomepage
path: root/dev/LibCompiler/ErrorOr.h
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-05-02 19:38:33 +0200
committerGitHub <noreply@github.com>2025-05-02 19:38:33 +0200
commit87979899ce833ca477bb563b84e3698224119dab (patch)
treedf67a0724de4c76ce594222747220c233c3bc7f5 /dev/LibCompiler/ErrorOr.h
parent3afc481dc64a07fe7fcaff9ce7a12a492c3ec8e7 (diff)
parentfb12b9730d78052f5cafbd84fbc9a830a22cec17 (diff)
Merge pull request #4 from nekernel-org/dev
0.0.1
Diffstat (limited to 'dev/LibCompiler/ErrorOr.h')
-rw-r--r--dev/LibCompiler/ErrorOr.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/dev/LibCompiler/ErrorOr.h b/dev/LibCompiler/ErrorOr.h
new file mode 100644
index 0000000..ca93dd2
--- /dev/null
+++ b/dev/LibCompiler/ErrorOr.h
@@ -0,0 +1,45 @@
+/*
+ * ========================================================
+ *
+ * LibCompiler
+ * Copyright (C) 2024-2025 Amlal El Mahrouss, all rights reserved.
+ *
+ * ========================================================
+ */
+
+#pragma once
+
+#include <LibCompiler/Defines.h>
+#include <LibCompiler/Ref.h>
+
+namespace LibCompiler {
+using ErrorT = UInt32;
+
+template <typename T>
+class ErrorOr final {
+ public:
+ ErrorOr() = default;
+ ~ErrorOr() = default;
+
+ public:
+ explicit ErrorOr(Int32 err) : mId(err) {}
+
+ explicit ErrorOr(nullPtr Null) {}
+
+ explicit ErrorOr(T Class) : mRef(Class) {}
+
+ ErrorOr& operator=(const ErrorOr&) = default;
+ ErrorOr(const ErrorOr&) = default;
+
+ Ref<T> Leak() { return mRef; }
+
+ operator bool() { return mRef; }
+
+ private:
+ Ref<T> mRef;
+ Int32 mId{0};
+};
+
+using ErrorOrAny = ErrorOr<voidPtr>;
+
+} // namespace LibCompiler