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

Adding support for stringifier functions in Kotlin #738

Merged

Conversation

emarteca
Copy link
Contributor

@emarteca emarteca commented Dec 3, 2024

Adding support for stringifier functions in Kotlin. This means, generating override fun toString(): String as the signature for a function annotated with the stringifier attribute.

This is specifically useful for allowing default printing of objects. If a Kotlin Result has an error type that overrides toString, then that toString is called to display the error, which is much more useful than the default toString that just prints the object address. With this PR, we can customize what's printed with the toString if the Result has a Rust-backed error type (by writing a valid to_string on the Rust side).

@emarteca emarteca marked this pull request as ready for review December 3, 2024 01:42
Copy link
Contributor

@Manishearth Manishearth left a comment

Choose a reason for hiding this comment

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

Not opposed to this way of solving this, but we already have the stringifier attribute, can we use that and have any method with stringifier automatically have its signature set to override fun toString()?

@emarteca
Copy link
Contributor Author

emarteca commented Dec 3, 2024

Oh, good point! I didn't find the stringifier attribute, I'll use that instead.

@emarteca emarteca changed the title Adding support for overriding functions in Kotlin Adding support for stringifier functions in Kotlin Dec 3, 2024
@emarteca emarteca merged commit 42f8e40 into rust-diplomat:main Dec 3, 2024
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants