Result Rt¶
| Spice | |
|---|---|
Result<T> struct¶
Result in Spice are wrappers around values, that allow to either provide a value or an error object. This is useful for functions that return a value, but also can fail. The error can then be dealt with on the caller side e.g. using the panic builtin.
Constructors¶
ctor¶
| Spice | |
|---|---|
Construct a successful result holding the given data
Parameters
| Name | Type | Description |
|---|---|---|
data |
const T& |
Data value to wrap |
ctor¶
| Spice | |
|---|---|
Construct a failed result holding the given error
Parameters
| Name | Type | Description |
|---|---|---|
error |
const Error& |
Error to wrap |
Methods¶
unwrap¶
| Spice | |
|---|---|
Returns the stored data object. If an error is present, this function will panic.
Returns: T&
getErr¶
| Spice | |
|---|---|
Return the enclosed error object.
Returns: Error&
isOk¶
| Spice | |
|---|---|
Checks if the result contains any data.
Returns: bool
isErr¶
| Spice | |
|---|---|
Checks if the result contains an error.
Returns: bool
Functions¶
ok¶
| Spice | |
|---|---|
Returns a result object with a value and no error.
Parameters
| Name | Type | Description |
|---|---|---|
data |
const T& |
Returns: Result<T>
err¶
| Spice | |
|---|---|
Returns a result object with an error and no value.
Parameters
| Name | Type | Description |
|---|---|---|
error |
const Error& |
Returns: Result<T>
err¶
| Spice | |
|---|---|
Returns a result object with an error and no value.
Parameters
| Name | Type | Description |
|---|---|---|
code |
int |
|
message |
string |
Returns: Result<T>
err¶
| Spice | |
|---|---|
Returns a result object with an error and no value.
Parameters
| Name | Type | Description |
|---|---|---|
message |
string |
Returns: Result<T>