Struct Unit
A unit type is a type that allows only one value and holds no information. It can be used as a placeholder in a Result<T, TErr> that returns no data.
Inherited Members
Namespace: RustyOptions
Assembly: RustyOptions.dll
Syntax
[Serializable]
[JsonConverter(typeof(UnitJsonConverter))]
public readonly struct Unit : IEquatable<Unit>, IComparable<Unit>, ISpanFormattable, IFormattable
Remarks
The unit type is similar to void
in C#, except that it is an actual value that
can be returned, and a type that can be used as a generic type parameters.
For RustyOptions, the main use of this type is to allow for Result
-returning methods
that do not return a value, but might return an error: Result<Unit, TErr>
Fields
| Edit this page View SourceDefault
Returns the Unit
instance.
Declaration
public static readonly Unit Default
Field Value
Type | Description |
---|---|
Unit |
Methods
| Edit this page View SourceCompareTo(Unit)
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
Declaration
public int CompareTo(Unit other)
Parameters
Type | Name | Description |
---|---|---|
Unit | other | An object to compare with this instance. |
Returns
Type | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|
int | A value that indicates the relative order of the objects being compared. The return value has these meanings:
|
Equals(Unit)
Indicates whether the current object is equal to another object of the same type.
Declaration
public bool Equals(Unit other)
Parameters
Type | Name | Description |
---|---|---|
Unit | other | An object to compare with this object. |
Returns
Type | Description |
---|---|
bool | true if the current object is equal to the |
Equals(object?)
Indicates whether this instance and a specified object are equal.
Declaration
public override bool Equals(object? obj)
Parameters
Type | Name | Description |
---|---|---|
object | obj | The object to compare with the current instance. |
Returns
Type | Description |
---|---|
bool | true if |
Overrides
| Edit this page View SourceGetHashCode()
Returns the hash code for this instance.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int | A 32-bit signed integer that is the hash code for this instance. |
Overrides
| Edit this page View SourceToString()
Returns the fully qualified type name of this instance.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | The fully qualified type name. |
Overrides
| Edit this page View SourceToString(string?, IFormatProvider?)
Formats the value of the current instance using the specified format.
Declaration
public string ToString(string? format, IFormatProvider? formatProvider)
Parameters
Type | Name | Description |
---|---|---|
string | format | The format to use. -or- A null reference ( |
IFormatProvider | formatProvider | The provider to use to format the value. -or- A null reference ( |
Returns
Type | Description |
---|---|
string | The value of the current instance in the specified format. |
TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)
Tries to format the value of the current instance into the provided span of characters.
Declaration
public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
Parameters
Type | Name | Description |
---|---|---|
Span<char> | destination | The span in which to write this instance's value formatted as a span of characters. |
int | charsWritten | When this method returns, contains the number of characters that were written in |
ReadOnlySpan<char> | format | A span containing the characters that represent a standard or custom format string that defines the acceptable format for |
IFormatProvider | provider | An optional object that supplies culture-specific formatting information for |
Returns
Type | Description |
---|---|
bool |
Operators
| Edit this page View Sourceoperator +(Unit, Unit)
The addition operator for Unit
.
Declaration
public static Unit operator +(Unit left, Unit right)
Parameters
Type | Name | Description |
---|---|---|
Unit | left | |
Unit | right |
Returns
Type | Description |
---|---|
Unit |
operator ==(Unit, Unit)
The equality operator for Unit
. Always returns true
.
Declaration
public static bool operator ==(Unit left, Unit right)
Parameters
Type | Name | Description |
---|---|---|
Unit | left | |
Unit | right |
Returns
Type | Description |
---|---|
bool |
operator >(Unit, Unit)
The greater-than operator for Unit
. Always returns false
.
Declaration
public static bool operator >(Unit left, Unit right)
Parameters
Type | Name | Description |
---|---|---|
Unit | left | |
Unit | right |
Returns
Type | Description |
---|---|
bool |
operator >=(Unit, Unit)
The greater-than-or-equal operator for Unit
. Always returns true
.
Declaration
public static bool operator >=(Unit left, Unit right)
Parameters
Type | Name | Description |
---|---|---|
Unit | left | |
Unit | right |
Returns
Type | Description |
---|---|
bool |
implicit operator ValueTuple(Unit)
Provides implicit conversion between Unit
and the empty ValueTuple
.
Declaration
public static implicit operator ValueTuple(Unit unit)
Parameters
Type | Name | Description |
---|---|---|
Unit | unit |
Returns
Type | Description |
---|---|
() |
implicit operator Unit(ValueTuple)
Provides implicit conversion between Unit
and the empty ValueTuple
.
Declaration
public static implicit operator Unit(ValueTuple tuple)
Parameters
Type | Name | Description |
---|---|---|
() | tuple |
Returns
Type | Description |
---|---|
Unit |
operator !=(Unit, Unit)
The inequality operator for Unit
. Always returns false
.
Declaration
public static bool operator !=(Unit left, Unit right)
Parameters
Type | Name | Description |
---|---|---|
Unit | left | |
Unit | right |
Returns
Type | Description |
---|---|
bool |
operator <(Unit, Unit)
The less-than operator for Unit
. Always returns false
.
Declaration
public static bool operator <(Unit left, Unit right)
Parameters
Type | Name | Description |
---|---|---|
Unit | left | |
Unit | right |
Returns
Type | Description |
---|---|
bool |
operator <=(Unit, Unit)
The less-than-or-equals operator for Unit
. Always returns true
.
Declaration
public static bool operator <=(Unit left, Unit right)
Parameters
Type | Name | Description |
---|---|---|
Unit | left | |
Unit | right |
Returns
Type | Description |
---|---|
bool |