A small collection of general-purpose utilities for .NET: an Option<T> and
Result<TOk, TErr> pair for Rust-style error/optionality handling, plus helpers for
formatting and parsing file sizes, SI-prefixed numbers and durations, a bit-vector
toolkit, and a no-op Stream.
Targets netstandard2.0, netstandard2.1 and net8.0.
dotnet add package TsuA struct-based optional value, avoiding null for "no value" cases.
using Tsu;
Option<int> some = Option.Some(42);
Option<int> none = Option.None<int>();
if (some.TryGetValue(out int value))
Console.WriteLine(value); // 42
int fallback = none.UnwrapOr(-1); // -1A struct-based result type for representing success or failure without exceptions.
using Tsu;
Result<int, string> Divide(int a, int b) =>
b == 0 ? Result.Err<int, string>("division by zero") : Result.Ok<int, string>(a / b);
Result<int, string> result = Divide(10, 2);
Console.WriteLine(result.UnwrapOr(-1)); // 5A type with exactly one possible value, useful as a placeholder generic argument
(e.g. Result<Unit, string> for operations that either succeed with no payload or
fail with an error).
Formatting and parsing of byte counts, with KiB/MiB/GiB/TiB/PiB/EiB
constants.
using Tsu.Numerics;
FileSize.Format(1536); // "1.5 KiB"
FileSize.TryParseInteger("2KiB", out long bytes); // bytes == 2048Formatting and parsing of numbers with SI prefixes (from Yocto to Yotta).
using Tsu.Numerics;
SI.Format(1500); // "1.5 k"
SI.Parse("1.5k"); // 1500Formatting of tick counts and TimeSpans into human-readable scaled durations
(hours down to nanoseconds).
using Tsu.Numerics;
Duration.Format(TimeSpan.FromMinutes(90)); // "01.50h"Low-level helpers for reading and writing individual bits within byte, ushort,
uint and ulong vectors (array/list and Span<T> overloads), plus
VariableLengthBitVector, a resizable bit vector built on top of them.
A Stream that discards everything written to it and throws on any read, akin to
piping to /dev/null.
dotnet restore --locked-mode
dotnet build --configuration Release
dotnet test --configuration ReleaseMIT License. See LICENSE for details.