Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API Proposal]: Implement IUtf8SpanParsable on Guid #105653

Closed
SirCxyrtyx opened this issue Jul 29, 2024 · 1 comment
Closed

[API Proposal]: Implement IUtf8SpanParsable on Guid #105653

SirCxyrtyx opened this issue Jul 29, 2024 · 1 comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners

Comments

@SirCxyrtyx
Copy link

SirCxyrtyx commented Jul 29, 2024

Background and motivation

As part of #81500 :

Implement IUtf8SpanParsable on Guid. Additionally, add a utf8 Parse and TryParse that do not take the unused IFormatProvider parameter. This matches how ISpanParsable was implemented.

Draft PR: #105654

API Proposal

namespace System;

public readonly partial struct Guid
    : ISpanFormattable,
      IComparable,
      IComparable<Guid>,
      IEquatable<Guid>,
      ISpanParsable<Guid>,
      IUtf8SpanFormattable,
+      IUtf8SpanParsable<Guid>
{
+    public static Guid Parse(ReadOnlySpan<byte> utf8Text);
+    public static bool TryParse(ReadOnlySpan<byte> utf8Text, out Guid result);

+    public static Guid Parse(ReadOnlySpan<byte> utf8Text, IFormatProvider? provider);
+    public static bool TryParse(ReadOnlySpan<byte> utf8Text, IFormatProvider? provider, out Guid result);
}

API Usage

var utf8GuidText = "{a8a110d5-fc49-43c5-bf46-802db8f843ff}"u8;

if (Guid.TryParse(utf8GuidText, out Guid guid))
{
    //do something with guid
}

Alternative Designs

No response

Risks

There are a few aspects to this that I am unsure about.

  • Given that the IFormatProvider parameter is unused, I think IUtf8SpanParsable ought to be implemented explicitly. But that would not be consistent with the ISpanParsable implementation.
  • Should a utf8 version of ParseExact and TryParseExact also be added for consistency?
  • Guid has a constructor that takes a string, which is the same as calling Guid.Parse(string). It also has a constructor that takes a ReadOnlySpan<byte>, but this will not be equivalent to calling Guid.Parse(ReadOnlySpan<byte>), as that constructor deserializes from a binary representation of a Guid. Is this inconsistency a problem?
@SirCxyrtyx SirCxyrtyx added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Jul 29, 2024
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jul 29, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Jul 29, 2024
@tannergooding
Copy link
Member

This is already approved by #81500, it just hasn't been implemented yet

@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Jul 29, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Aug 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners
Projects
None yet
Development

No branches or pull requests

2 participants