File tree 3 files changed +33
-3
lines changed
3 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -69,9 +69,9 @@ Package::tryFromToml(const toml::value& val) noexcept {
69
69
auto edition = Try (Edition::tryFromString (
70
70
Try (toml::try_find<std::string>(val, " package" , " edition" ))
71
71
));
72
- auto version =
73
- Version::parse ( Try (toml::try_find<std::string>(val, " package" , " version" ))
74
- );
72
+ auto version = Try ( Version::tryParse (
73
+ Try (toml::try_find<std::string>(val, " package" , " version" ))
74
+ ) );
75
75
return Ok (Package (std::move (name), std::move (edition), std::move (version)));
76
76
}
77
77
Original file line number Diff line number Diff line change @@ -469,18 +469,44 @@ Prerelease::parse(const std::string_view str) {
469
469
VersionParser parser (str);
470
470
return parser.parsePre ();
471
471
}
472
+ Result<Prerelease>
473
+ Prerelease::tryParse (const std::string_view str) noexcept {
474
+ try {
475
+ return Ok (parse (str));
476
+ } catch (const SemverError& e) {
477
+ Bail (e.what ());
478
+ }
479
+ }
472
480
473
481
BuildMetadata
474
482
BuildMetadata::parse (const std::string_view str) {
475
483
VersionParser parser (str);
476
484
return parser.parseBuild ();
477
485
}
486
+ Result<BuildMetadata>
487
+ BuildMetadata::tryParse (const std::string_view str) noexcept {
488
+ try {
489
+ return Ok (parse (str));
490
+ } catch (const SemverError& e) {
491
+ Bail (e.what ());
492
+ }
493
+ }
478
494
479
495
Version
480
496
Version::parse (const std::string_view str) {
481
497
VersionParser parser (str);
482
498
return parser.parse ();
483
499
}
500
+ Result<Version>
501
+ Version::tryParse (const std::string_view str) noexcept {
502
+ try {
503
+ return Ok (parse (str));
504
+ } catch (const SemverError& e) {
505
+ Bail (e.what ());
506
+ }
507
+ }
508
+
509
+ // FIXME: remove exceptions and use Result entirely.
484
510
485
511
#ifdef CABIN_TEST
486
512
Original file line number Diff line number Diff line change 10
10
#pragma once
11
11
12
12
#include " Exception.hpp"
13
+ #include " Rustify/Result.hpp"
13
14
14
15
#include < cstddef>
15
16
#include < cstdint>
@@ -57,6 +58,7 @@ struct Prerelease {
57
58
std::vector<VersionToken> ident;
58
59
59
60
static Prerelease parse (std::string_view str);
61
+ static Result<Prerelease> tryParse (std::string_view str) noexcept ;
60
62
bool empty () const noexcept ;
61
63
std::string toString () const noexcept ;
62
64
};
@@ -71,6 +73,7 @@ struct BuildMetadata {
71
73
std::vector<VersionToken> ident;
72
74
73
75
static BuildMetadata parse (std::string_view str);
76
+ static Result<BuildMetadata> tryParse (std::string_view str) noexcept ;
74
77
bool empty () const noexcept ;
75
78
std::string toString () const noexcept ;
76
79
};
@@ -83,6 +86,7 @@ struct Version {
83
86
BuildMetadata build;
84
87
85
88
static Version parse (std::string_view str);
89
+ static Result<Version> tryParse (std::string_view str) noexcept ;
86
90
std::string toString () const noexcept ;
87
91
};
88
92
std::ostream& operator <<(std::ostream& os, const Version& ver) noexcept ;
You can’t perform that action at this time.
0 commit comments