Show / Hide Table of Contents

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.

Implements
IEquatable<Unit>
IComparable<Unit>
ISpanFormattable
IFormattable
Inherited Members
object.Equals(object, object)
object.GetType()
object.ReferenceEquals(object, object)
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 Source

Default

Returns the Unit instance.

Declaration
public static readonly Unit Default
Field Value
Type Description
Unit

Methods

| Edit this page View Source

CompareTo(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:

Value Meaning
Less than zero This instance precedes other in the sort order.
Zero This instance occurs in the same position in the sort order as other.
Greater than zero This instance follows other in the sort order.
| Edit this page View Source

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 other parameter; otherwise, false.

| Edit this page View Source

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 obj and this instance are the same type and represent the same value; otherwise, false.

Overrides
ValueType.Equals(object)
| Edit this page View Source

GetHashCode()

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
ValueType.GetHashCode()
| Edit this page View Source

ToString()

Returns the fully qualified type name of this instance.

Declaration
public override string ToString()
Returns
Type Description
string

The fully qualified type name.

Overrides
ValueType.ToString()
| Edit this page View Source

ToString(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 (Nothing in Visual Basic) to use the default format defined for the type of the IFormattable implementation.

IFormatProvider formatProvider

The provider to use to format the value.

-or-

A null reference (Nothing in Visual Basic) to obtain the numeric format information from the current locale setting of the operating system.

Returns
Type Description
string

The value of the current instance in the specified format.

| Edit this page View Source

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 destination.

ReadOnlySpan<char> format

A span containing the characters that represent a standard or custom format string that defines the acceptable format for destination.

IFormatProvider provider

An optional object that supplies culture-specific formatting information for destination.

Returns
Type Description
bool

true if the formatting was successful; otherwise, false.

Operators

| Edit this page View Source

operator +(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
| Edit this page View Source

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
| Edit this page View Source

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
| Edit this page View Source

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
| Edit this page View Source

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
()
| Edit this page View Source

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
| Edit this page View Source

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
| Edit this page View Source

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
| Edit this page View Source

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

Implements

IEquatable<T>
IComparable<T>
ISpanFormattable
IFormattable

Extension Methods

OptionExtensions.None<T>(T)
OptionExtensions.Some<T>(T)
  • Edit this page
  • View Source
In this article
Back to top Generated by DocFX