@@ -41,6 +41,7 @@ test contains {
41
41
/// members of BaseErrorSet, but not members of ToExcludeErrorSet.
42
42
/// ToExcludeErrorSet does not have to
43
43
/// be contained in, or even intersect BaseErrorSet.
44
+ /// See also `ExcludingAssertAllContained`.
44
45
pub fn Excluding (comptime BaseErrorSet : type , comptime ToExcludeErrorSet : type ) type {
45
46
if (BaseErrorSet == ToExcludeErrorSet ) return error {}; //allows excluding anyerror from anyerror
46
47
@@ -72,6 +73,7 @@ test Excluding {
72
73
/// Returns an error set with all members of BaseErrorSet
73
74
/// except for error_to_exclude.
74
75
/// error_to_exclude does not have to be a member of BaseErrorSet.
76
+ /// See also `WithoutAssertContained`.
75
77
pub fn Without (comptime BaseErrorSet : type , comptime error_to_exclude : anyerror ) type {
76
78
const ErrorSetToExclude = @TypeOf (@field (anyerror , @errorName (error_to_exclude )));
77
79
return comptime Excluding (BaseErrorSet , ErrorSetToExclude );
@@ -89,6 +91,7 @@ test Without {
89
91
/// Returns an error set with all errors which are
90
92
/// members of both ErrorSetA and ErrorSetB.
91
93
/// The resulting error set may be empty.
94
+ /// See also `IntersectAssertNonEmpty`.
92
95
pub fn Intersect (comptime ErrorSetA : type , comptime ErrorSetB : type ) type {
93
96
if (ErrorSetA == anyerror ) return ErrorSetB ; //allows intersecting with anyerror
94
97
@@ -116,3 +119,29 @@ test Intersect {
116
119
assert (Intersect (error {}, error {}) == error {});
117
120
}
118
121
}
122
+
123
+ /// Returns the set of errors that are
124
+ /// members of BaseErrorSet, but not members of ToExcludeErrorSet.
125
+ /// Asserts that all members of ToExcludeErrorSet are members of BaseErrorSet.
126
+ /// See also `Excluding`.
127
+ pub fn ExcludingAssertAllContained (comptime BaseErrorSet : type , comptime ToExcludeErrorSet : type ) type {
128
+ comptime assert (containsAll (BaseErrorSet , ToExcludeErrorSet ));
129
+ return comptime Excluding (BaseErrorSet , ToExcludeErrorSet );
130
+ }
131
+ /// Returns an error set with all members of BaseErrorSet
132
+ /// except for error_to_exclude.
133
+ /// Asserts that error_to_exclude is a member of BaseErrorSet.
134
+ /// See also `Without`.
135
+ pub fn WithoutAssertContained (comptime BaseErrorSet : type , comptime error_to_exclude : anyerror ) type {
136
+ comptime assert (contains (BaseErrorSet , error_to_exclude ));
137
+ return comptime Without (BaseErrorSet , error_to_exclude );
138
+ }
139
+ /// Returns an error set with all errors which are
140
+ /// members of both ErrorSetA and ErrorSetB.
141
+ /// Asserts that the resulting error set is not empty.
142
+ /// See also `Intersect`.
143
+ pub fn IntersectAssertNonEmpty (comptime ErrorSetA : type , comptime ErrorSetB : type ) type {
144
+ const Result = Intersect (ErrorSetA , ErrorSetB );
145
+ comptime assert (Result != error {});
146
+ return Result ;
147
+ }
0 commit comments