From 637bf968d1c2e60c6d51b10550233971424a0c6d Mon Sep 17 00:00:00 2001 From: ncave <777696+ncave@users.noreply.github.com> Date: Thu, 26 Sep 2024 16:32:38 -0700 Subject: [PATCH] [Rust] Uncurry field types for object expressions --- src/Fable.Cli/CHANGELOG.md | 1 + src/Fable.Transforms/Rust/Fable2Rust.fs | 5 ++++- .../src/FSharp.Collections.fs | 21 +++++++++++++++++++ .../src/Fable.Library.Rust.fsproj | 1 + 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/fable-library-rust/src/FSharp.Collections.fs diff --git a/src/Fable.Cli/CHANGELOG.md b/src/Fable.Cli/CHANGELOG.md index ac3912d10..9f8d4e6ed 100644 --- a/src/Fable.Cli/CHANGELOG.md +++ b/src/Fable.Cli/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed * [GH-3900](https://github.com/fable-compiler/Fable/pull/3900) [Python] Fix nuget packages with hypens in their names (by @MangelMaxime) +* [Rust] Uncurry field types for object expressions (by @ncave) ## 4.21.0 - 2024-09-19 diff --git a/src/Fable.Transforms/Rust/Fable2Rust.fs b/src/Fable.Transforms/Rust/Fable2Rust.fs index 4cc629912..6d936c8b8 100644 --- a/src/Fable.Transforms/Rust/Fable2Rust.fs +++ b/src/Fable.Transforms/Rust/Fable2Rust.fs @@ -2116,7 +2116,10 @@ module Util = memberDecl ) - let fieldIdents = fieldsMap.Values |> Seq.toList + let fieldIdents = + fieldsMap.Values + |> Seq.map (fun ident -> { ident with Type = FableTransforms.uncurryType ident.Type }) + |> Seq.toList let fields = fieldIdents diff --git a/src/fable-library-rust/src/FSharp.Collections.fs b/src/fable-library-rust/src/FSharp.Collections.fs new file mode 100644 index 000000000..1a5573fd5 --- /dev/null +++ b/src/fable-library-rust/src/FSharp.Collections.fs @@ -0,0 +1,21 @@ +namespace FSharp.Collections + +open System.Collections.Generic + +module HashIdentity = + let FromFunctions<'T> hasher equals : IEqualityComparer<'T> = + EqualityComparer<'T>.Create(equals, hasher) + + let Structural<'T when 'T: equality> : IEqualityComparer<'T> = + EqualityComparer<'T> + .Create(LanguagePrimitives.GenericEquality, LanguagePrimitives.GenericHash) + + let Reference<'T when 'T: not struct> : IEqualityComparer<'T> = + EqualityComparer<'T> + .Create(LanguagePrimitives.PhysicalEquality, LanguagePrimitives.PhysicalHash) + +module ComparisonIdentity = + let FromFunction<'T> comparer : IComparer<'T> = Comparer<'T>.Create(comparer) + + let Structural<'T when 'T: comparison> : IComparer<'T> = + Comparer<'T>.Create(LanguagePrimitives.GenericComparison) diff --git a/src/fable-library-rust/src/Fable.Library.Rust.fsproj b/src/fable-library-rust/src/Fable.Library.Rust.fsproj index 1365dbd30..2e7c8e0b5 100644 --- a/src/fable-library-rust/src/Fable.Library.Rust.fsproj +++ b/src/fable-library-rust/src/Fable.Library.Rust.fsproj @@ -18,6 +18,7 @@ +