Skip to content

Commit

Permalink
karm-base: Added lifetimebound anotations to Opt<> and Res<>.
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepy-monax committed Nov 12, 2024
1 parent 556a295 commit 606da51
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
20 changes: 10 additions & 10 deletions src/libs/karm-base/opt.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,36 +141,36 @@ struct [[nodiscard]] Opt {
return _present;
}

always_inline constexpr T *operator->() {
always_inline constexpr T *operator->() lifetimebound {
if (not _present) [[unlikely]]
panic("unwrapping None");

return &_value;
}

always_inline constexpr T &operator*() {
always_inline constexpr T &operator*() lifetimebound {
if (not _present) [[unlikely]]
panic("unwrapping None");

return _value;
}

always_inline constexpr T const *operator->() const {
always_inline constexpr T const *operator->() const lifetimebound {
if (not _present) [[unlikely]]
panic("unwrapping None");

return &_value;
}

always_inline constexpr T const &operator*() const {
always_inline constexpr T const &operator*() const lifetimebound {
if (not _present) [[unlikely]]
panic("unwrapping None");

return _value;
}

template <typename... Args>
always_inline constexpr T &emplace(Args &&...args) {
always_inline constexpr T &emplace(Args &&...args) lifetimebound {
clear();
_present = true;
std::construct_at(&_value, std::forward<Args>(args)...);
Expand All @@ -188,31 +188,31 @@ struct [[nodiscard]] Opt {
return NONE;
}

always_inline constexpr T &unwrap(char const *msg = "unwraping none") {
always_inline constexpr T &unwrap(char const *msg = "unwraping none") lifetimebound {
if (not _present) [[unlikely]]
panic(msg);
return _value;
}

always_inline constexpr T const &unwrap(char const *msg = "unwraping none") const {
always_inline constexpr T const &unwrap(char const *msg = "unwraping none") const lifetimebound {
if (not _present) [[unlikely]]
panic(msg);
return _value;
}

always_inline constexpr T const &unwrapOr(T const &other) const {
always_inline constexpr T const &unwrapOr(T const &other) const lifetimebound {
if (_present)
return _value;
return other;
}

always_inline constexpr T unwrapOrDefault(T other) const {
always_inline constexpr T unwrapOrDefault(T other) const lifetimebound {
if (_present)
return _value;
return other;
}

always_inline constexpr T unwrapOrElse(auto f) const {
always_inline constexpr T unwrapOrElse(auto f) const lifetimebound {
if (_present)
return _value;
return f();
Expand Down
8 changes: 4 additions & 4 deletions src/libs/karm-base/res.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,28 @@ struct [[nodiscard]] Res {
return _inner.template is<Ok<V>>();
}

always_inline constexpr E const &none() const {
always_inline constexpr E const &none() const lifetimebound {
if (not _inner.template is<E>()) [[unlikely]]
panic("none() called on an ok");

return _inner.template unwrap<E>();
}

always_inline constexpr V &unwrap(char const *msg = "unwraping an error") {
always_inline constexpr V &unwrap(char const *msg = "unwraping an error") lifetimebound {
if (not _inner.template is<Ok<V>>()) [[unlikely]]
panic(msg);

return _inner.template unwrap<Ok<V>>().inner;
}

always_inline constexpr V const &unwrap(char const *msg = "unwraping an error") const {
always_inline constexpr V const &unwrap(char const *msg = "unwraping an error") const lifetimebound {
if (not _inner.template is<Ok<V>>()) [[unlikely]]
panic(msg);

return _inner.template unwrap<Ok<V>>().inner;
}

always_inline constexpr V const &unwrapOr(V const &other) const {
always_inline constexpr V const &unwrapOr(V const &other) const lifetimebound {
if (_inner.template is<Ok<V>>())
return _inner.template unwrap<Ok<V>>().inner;
return other;
Expand Down
4 changes: 2 additions & 2 deletions src/libs/karm-io/impls.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ struct BufWriter :
public Seeker {

MutBytes _buf;
usize _pos;
usize _pos = 0;

BufWriter(MutBytes buf) : _buf(buf), _pos(0) {}
BufWriter(MutBytes buf) : _buf(buf) {}

Res<usize> seek(Seek seek) override {
_pos = seek.apply(_pos, sizeOf(_buf));
Expand Down

0 comments on commit 606da51

Please sign in to comment.