Skip to content

Conversation

@mamcx
Copy link
Contributor

@mamcx mamcx commented Nov 27, 2025

Description of Changes

Closes #3673

NOTE: C++ part will be in another PR

Expected complexity level and risk

2

Adding a new type touch everywhere

Testing

  • Adding smoke and unit test

@mamcx mamcx self-assigned this Nov 27, 2025
@mamcx mamcx added the release-any To be landed in any release window label Nov 27, 2025
@mamcx mamcx force-pushed the mamcx/result-type branch from 70ca89a to 4324cd7 Compare November 27, 2025 18:50
@mamcx mamcx requested a review from gefjon November 27, 2025 19:01
@JasonAtClockwork
Copy link
Contributor

I'll build out an attached PR to add the new functionality for the Unreal SDK.

@mamcx mamcx force-pushed the mamcx/result-type branch 3 times, most recently from 5a99c91 to cf9dd2f Compare December 15, 2025 15:20
@mamcx mamcx marked this pull request as ready for review December 15, 2025 16:50
Copy link
Contributor

@JasonAtClockwork JasonAtClockwork left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is updates to the /modules/sdk-test-cs but this won't be enough testing for the C# side. We'll need to add tests into the /sdks/csharp/examples~/regression-tests like for UUID to make sure this works end-to-end.

@rekhoff - I'll also want your eyes on this one when you can for the C# side

Copy link
Contributor

@gefjon gefjon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with the Rust parts of this PR. We'll still need review from the other languages' maintainers.

Copy link
Contributor

@rekhoff rekhoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The C# side looks good. I did some local testing of end-to-end behavior, and things look good.

Copy link
Collaborator

@coolreader18 coolreader18 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable to me, except for my one comment.

}

/// Converts `self` into an `Result<AlgebraicValue, AlgebraicValue>`, if applicable.
pub fn into_result(self) -> Result<Self, Self> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be -> Result<Result<AlgebraicType, AlgebraicType>, Self>?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mm, this is like the option variant:

/// Converts `self` into an `Option<AlgebraicValue>`, if applicable.
    pub fn into_option(self) -> Result<Option<Self>, Self> {
        match self {
            AlgebraicValue::Sum(sum_value) => match sum_value.tag {
                0 => Ok(Some(*sum_value.value)),
                1 => Ok(None),
                _ => Err(AlgebraicValue::Sum(sum_value)),
            },
            _ => Err(self),
        }
    }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the equivalent would be:

pub fn into_result(self) -> Result<Result<Self, Self>, Self> {
  match self {
    AlgebraicValue::Sum(sum_value) => match sum_value.tag {
      0 => Ok(Ok(*sum_value.value)),
      1 => Ok(Err(*sum_value.value)),
      _ => Err(self),
    },
    _ => Err(self),
  }
}

This way, it's possible to distinguish between the case where self is a Result::Err (so you get Ok(Err(val)), and the case where self is not a Result at all (so you get Err(self)). Your version sends both Result::Err and non-result values to Err.

@mamcx mamcx force-pushed the mamcx/result-type branch 3 times, most recently from 604c452 to c7b1f53 Compare December 29, 2025 20:52
@mamcx mamcx force-pushed the mamcx/result-type branch 2 times, most recently from 32ebe84 to bd8dba7 Compare December 31, 2025 15:22
@mamcx mamcx force-pushed the mamcx/result-type branch from bd8dba7 to d5bd9e0 Compare December 31, 2025 15:23
@JasonAtClockwork JasonAtClockwork self-requested a review December 31, 2025 20:21
Copy link
Contributor

@JasonAtClockwork JasonAtClockwork left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a couple comments but otherwise this looks like a solid fix for tests on the C# side!

}

public InsertWithTxRollbackResult()
{
Copy link
Contributor

@JasonAtClockwork JasonAtClockwork Dec 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll either want to have required keyword added to the generated use of SpacetimeDB.Result<> or add a default in the empty constructor like:

this.Value = default!

@rekhoff - Do you have any preference, without this devs will have ugly warnings using Result<> in C#?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the warning devs will see:
warning CS8618: Non-nullable field 'Msg' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No strong preference here, but I think I lean towards the default empty constructor. If a developer doesn't actually care about the results, marking it as required could be kind of annoying to them.

@mamcx mamcx force-pushed the mamcx/result-type branch from a85626f to 370e005 Compare December 31, 2025 20:52
@mamcx mamcx force-pushed the mamcx/result-type branch from 370e005 to 6898dc4 Compare December 31, 2025 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-any To be landed in any release window

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement SpacetimeType for Result<T, E>

6 participants