diff options
| author | William Boman <william@redwill.se> | 2022-10-05 20:33:21 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-05 20:33:21 +0200 |
| commit | 738684097dfdd9a4a67cd217b0beda3e169bd85d (patch) | |
| tree | d2eb8485dedcac66061b0d99ad7f810828911073 /lua/mason-core/optional.lua | |
| parent | test(cargo): stub crates.io http call (#508) (diff) | |
| download | mason-738684097dfdd9a4a67cd217b0beda3e169bd85d.tar mason-738684097dfdd9a4a67cd217b0beda3e169bd85d.tar.gz mason-738684097dfdd9a4a67cd217b0beda3e169bd85d.tar.bz2 mason-738684097dfdd9a4a67cd217b0beda3e169bd85d.tar.lz mason-738684097dfdd9a4a67cd217b0beda3e169bd85d.tar.xz mason-738684097dfdd9a4a67cd217b0beda3e169bd85d.tar.zst mason-738684097dfdd9a4a67cd217b0beda3e169bd85d.zip | |
feat(cargo): improve handling of git-based crates (#512)
This is all pretty overkill, especially considering the small amount of
packages based on git-based crates.
Diffstat (limited to 'lua/mason-core/optional.lua')
| -rw-r--r-- | lua/mason-core/optional.lua | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lua/mason-core/optional.lua b/lua/mason-core/optional.lua index 65317b7f..6eb0719e 100644 --- a/lua/mason-core/optional.lua +++ b/lua/mason-core/optional.lua @@ -105,4 +105,14 @@ function Optional:is_present() return self._value ~= nil end +---@param err fun(): any +function Optional:ok_or(err) + local Result = require "mason-core.result" + if self:is_present() then + return Result.success(self:get()) + else + return Result.failure(err()) + end +end + return Optional |
