TResult<T, E>
Represents a result type that can either contain a success value or an error. Similar to Rust's Result type.
Definition
Unit: Neslib.Iceoryx2.System
Type Parameters
T: The type of the success value
E:
Properties
| Name | Description |
|---|---|
| Error | The error value in case IsErr=True. Otherwise undefined. |
| ErrorString | The error value as a string in case IsErr=True. Otherwise empty. When E is an enumerated type, this returns the string representation of the enum value. Otherwise an empty string; |
| HasValue | Returns True if the result is Ok. |
| IsErr | Returns True if the result is Err. |
| IsOk | Returns True if the result is Ok. |
Methods
| Name | Description |
|---|---|
| Err | Creates an error result. |
| Expect | Unwraps the success value, throwing an exception if the result is an error. |
| InitErr | Creates an error result. |
| InitOk | Creates a success result. |
| Ok | Creates a success result. |
| ToString | Returns a string representation of the result, indicating whether it is a success or an error. |
| Value | Unwraps the success value, throwing an exception if the result is an error. |
| ValueOr | Returns the success value or a default value if the result is an error. |
Property Descriptions
Error
The error value in case IsErr=True. Otherwise undefined.
property Error: E read FError
Type: E
ErrorString
The error value as a string in case IsErr=True. Otherwise empty. When E is an enumerated type, this returns the string representation of the enum value. Otherwise an empty string;
property ErrorString: String read GetErrorString
Type: String
HasValue
Returns True if the result is Ok.
property HasValue: Boolean read FIsOk
Type: Boolean
IsErr
Returns True if the result is Err.
property IsErr: Boolean read GetIsErr
Type: Boolean
IsOk
Returns True if the result is Ok.
property IsOk: Boolean read FIsOk
Type: Boolean
Method Descriptions
Err(E)
Creates an error result.
class function Err(const AError: E): TResult<T, E>; static
Parameters
AError: E
Returns
Expect(String)
Unwraps the success value, throwing an exception if the result is an error.
function Expect(const AMessage: String): T; inline
Parameters
AMessage: String
Returns
T
InitErr(E)
Creates an error result.
procedure InitErr(const AError: E)
Parameters
AError: E
InitOk(T)
Creates a success result.
procedure InitOk(const AValue: T)
Parameters
AValue: T
Ok(T)
Creates a success result.
class function Ok(const AValue: T): TResult<T, E>; static
Parameters
AValue: T
Returns
ToString
Returns a string representation of the result, indicating whether it is a success or an error.
function ToString: String
Returns
String: A string in the format 'Ok' if the result is a success, or 'Err(ErrorString)' if the result is an error.
Value
Unwraps the success value, throwing an exception if the result is an error.
function Value: T; inline
Returns
T
ValueOr(T)
Returns the success value or a default value if the result is an error.
function ValueOr(const ADefaultValue: T): T; inline
Parameters
ADefaultValue: T
Returns
T