@@ -26,9 +26,19 @@ module TypeExtensions =
2626 [<MethodImpl( MethodImplOptions.AggressiveInlining) >]
2727 member x.AsFSharpResult () =
2828 match x.IsOk() with
29- | ( true , value) -> Ok value
29+ | ( true , value) -> Ok( value)
3030 | _ -> Error( x.UnwrapErr())
3131
32+ type RustyOptions.Unit with
33+ /// Converts a RustyOptions Unit into an F# unit.
34+ [<MethodImpl( MethodImplOptions.AggressiveInlining) >]
35+ member _.AsFSharpUnit () : unit = ()
36+
37+ type Microsoft.FSharp.Core.Unit with
38+ /// Converts an F# unit into a RustyOptions Unit.
39+ [<MethodImpl( MethodImplOptions.AggressiveInlining) >]
40+ member _.AsRustyUnit () = RustyOptions.Unit.Default
41+
3242#if NET7_ 0_ OR_ GREATER
3343 type RustyOptions.NumericOption < 'a when 'a : struct and 'a :> System.ValueType and 'a : ( new : unit -> 'a ) and 'a :> System.Numerics.INumber < 'a >> with
3444
@@ -75,6 +85,17 @@ module CSharpTypeExtensions =
7585 | ( true , value) -> Ok value
7686 | _ -> Error( x.UnwrapErr())
7787
88+ /// Converts a RustyOptions Unit Result into an F# unit Result.
89+ [<Extension>]
90+ [<MethodImpl( MethodImplOptions.AggressiveInlining) >]
91+ let AsFSharpUnitResult ( x : RustyOptions.Result < RustyOptions.Unit , 'err >) =
92+ match x.IsOk() with
93+ | ( true , _) -> Ok ()
94+ | _ -> Error( x.UnwrapErr())
95+
96+ // NOTE: We can't have an AsFSharpUnit method for C#, because C# interprets
97+ // a unit-returning F# function as if it's a void-returning C# function.
98+
7899#if NET7_ 0_ OR_ GREATER
79100/// This module provides C# extension methods on RustyOptions numeric types.
80101[<Extension>]
@@ -176,3 +197,17 @@ module Result =
176197 match x with
177198 | Ok( value) -> RustyOptions.Result.Ok< 'a, 'err>( value)
178199 | Error( err) -> RustyOptions.Result.Err< 'a, 'err>( err)
200+
201+ /// Converts a RustyOptions Unit Result into an F# unit Result.
202+ [<MethodImpl( MethodImplOptions.AggressiveInlining) >]
203+ let ofRustyUnitResult ( x : RustyOptions.Result < RustyOptions.Unit , 'err >) =
204+ match x.IsOk() with
205+ | ( true , _) -> Ok ()
206+ | _ -> Error( x.UnwrapErr())
207+
208+ /// Converts an F# unit Result into a RustyOptions Unit Result.
209+ [<MethodImpl( MethodImplOptions.AggressiveInlining) >]
210+ let toRustyUnitResult ( x : Result < unit , 'err >) =
211+ match x with
212+ | Ok(_) -> RustyOptions.Result.Ok< RustyOptions.Unit, 'err>( RustyOptions.Unit.Default)
213+ | Error( err) -> RustyOptions.Result.Err< RustyOptions.Unit, 'err>( err)
0 commit comments