Closed fitzchivalrik closed 7 months ago
For example, if Point is part of some module then the fields x and y would be private to the code that's external to the module.
Yeah, I was debating whether that should be mentioned explicitly, or if it would complicate things too much.
I decided to not mention it, because I thought it is the same for with
; as in, the fields need to be accessible at call site to be able to use with
:
using System;
public readonly record struct Point {
internal readonly int X {get; init;}
private readonly int Y {get; init;}
public Point(int x, int y) => (X,Y)=(x,y);
public override String ToString() => $"Point {{ X = {this.X}, Y= {this.Y} }}";
}
public class Program
{
public static void Main()
{
var pt = new Point(123, 456);
pt = pt with { X = 789 }; // Error if `X` is declared private above, or if `Main()` is in another project/module.
Console.WriteLine(pt.ToString()); // prints: Point { X = 789, Y = 456 }
}
}
I thought it is the same for
with
; as in, the fields need to be accessible at call site to be able to usewith
Right, but in the C# example, X
and Y
are properties, not fields, and so it's comparing apples to oranges.
but in the C# example, X and Y are properties, not fields,
Ah, yeah, fair point! Thank you!
I updated it according to the suggestions - at least, I hope I understood them correctly ^^. I am not sure, however, if the last bit with the 'bake into type' still makes sense there, or if it maybe should be changed to a 'copy'-style update, instead of a consuming one.
@fitzchivalrik If you could agree to the CLA then I can get this merged. Thanks!
@atifaziz No worries, thanks for coming back to it. Unfortunately, I do not really want to agree to the CLA. (I am unsure if this contribution even passes the threshold of originality, but I am not a lawyer, of course.)
If this causes complications, I would be open to agree to the CLA only for this specific contribution (and not in general), if this is at all possible.
If this causes complications, I would be open to agree to the CLA only for this specific contribution (and not in general), if this is at all possible.
@fitzchivalrik I understand. How about this? You sign it now for this contribution and if you feel uncomfortable with the CLA at any point thereafter and want to revoke it for future contributions, you always have the option to terminate the agreement by issuing the following command:
@microsoft-github-policy-service terminate
However, I'd encourage you to seek clarity on the CLA so you're eventually comfortable with it because we appreciate and value your contributions!
Sorry for the delay. Thanks for the terminate command - agreeing, and then terminating it later here is fine for me. @microsoft-github-policy-service agree
@microsoft-github-policy-service terminate
@fitzchivalrik please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
@microsoft-github-policy-service agree [company="{your company}"]
Options:
- (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
- (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"
When talking about the
with
expression in C#, mention the struct update syntax^1 as something similar in Rust.