RustyOptions 0.5.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package RustyOptions --version 0.5.0
NuGet\Install-Package RustyOptions -Version 0.5.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RustyOptions" Version="0.5.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RustyOptions" Version="0.5.0" />
<PackageReference Include="RustyOptions" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RustyOptions --version 0.5.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: RustyOptions, 0.5.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package RustyOptions@0.5.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RustyOptions&version=0.5.0
#tool nuget:?package=RustyOptions&version=0.5.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
RustyOptions
Option and Result types for C#, inspired by Rust
Avoid Null-Reference Errors
The C# nullable reference types feature is useful, but it's entirely optional, and the warnings it produces are easily ignored.
RustyOptions uses the type system to:
- Make it impossible to access a possibly-missing value without first checking if the value is present.
- Clearly express your intent in the API you build. If a method might not return a value, or might return an error message instead of a value, you can express this in the return type where it can't be missed.
Safely Chain Together Fallible Methods
var output = Option.Parse<int>(userInput)
.AndThen(ValidateRange)
.OrElse(() => defaultsByGroup.GetValueOrNone(user.GroupId))
.MapOr(PillWidget.Render, string.Empty);
The example above does the following:
- Attempts to parse the user input into an integer.
- If the parsing succeeds, passes the resulting number to the
ValidateRangemethod, which returnsSome(parsedInput)if the parsed input is within the valid range, orNoneif it falls outside the valid range. - If either steps 1 or 2 fail, we attempt to do a dictionary lookup to get a default value using the current user's group ID.
- If at the end we have a value, we render it to a string. Otherwise, we set
outputto an empty string.
Uses Modern .NET Features
For performance and convenience:
- Supports parsing any type that implements
IParsable<T>orISpanParsable<T>(.NET 7 and above only) - The
NumericOption<T>type supports generic math for any contained type that implementsINumber<T>(.NET 7 and above only) - Supports
asyncandIAsyncEnumerable<T>. - Supports nullable type annotations.
- Supports serialization and deserialization with
System.Text.Json. IEquatable<T>andIComparable<T>allowOptionandResulttypes to be easily compared and sorted.IFormattableandISpanFormattableallowOptionandResultto efficiently format their content.OptionandResultcan be efficiently converted toReadOnlySpan<T>orIEnumerable<T>for easier interop with existing code.- Convenient extension methods for working with dictionaries (
GetValueOrNone), collections (FirstOrNone), enums (Option.ParseEnum) and more.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
NuGet packages (3)
Showing the top 3 NuGet packages that depend on RustyOptions:
| Package | Downloads |
|---|---|
|
RustyOptions.FSharp
F# support for RustyOptions |
|
|
Veer.Abp.ChatModule.Domain.Shared
ChatModule – Domain Shared layer |
|
|
oml
Package Description |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on RustyOptions:
| Repository | Stars |
|---|---|
|
MCSLTeam/MCServerLauncher-Future
Future version of MCSL, a brand new server management tool. Redefined, Versatile, Easy to use. (WPF Launcher & Daemon)
|