Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@joncinque
Copy link
Collaborator

Problem

The ToStr trait is a bit difficult to use, forcing a lot of redundant uses of types, when programs will just want to call err.to_str::<MyError>().

Summary of changes

Simplify the trait to not require anything, then add a generic to_str function directly on ProgramError that allows us to get the error message for a particular error type.

Also, clarify the deprecation warning on DecodeError.

BREAKING CHANGE: the ToStr trait requires fewer bounds

@joncinque joncinque requested a review from febo June 6, 2025 20:52
@joncinque joncinque added the breaking PR contains breaking changes label Jun 6, 2025
@joncinque
Copy link
Collaborator Author

#191 will address the CI failure

pub trait ToStr {
fn to_str<E>(&self) -> &'static str
where
E: 'static + ToStr + TryFrom<u32>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Super nice!

Copy link
Contributor

@febo febo left a comment

Choose a reason for hiding this comment

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

Looks great!

@febo
Copy link
Contributor

febo commented Jun 6, 2025

BREAKING CHANGE: the ToStr trait requires fewer bounds

Is requiring fewer bounds a breaking change?

@febo
Copy link
Contributor

febo commented Jun 6, 2025

BREAKING CHANGE: the ToStr trait requires fewer bounds

Is requiring fewer bounds a breaking change?

Ah, it is on the to_str method.

#### Problem

The `ToStr` trait is a bit difficult to use, forcing a lot of redundant
uses of types, when programs will just want to call
`err.to_str::<MyError>()`.

#### Summary of changes

Simplify the trait to not require anything, then add a generic `to_str`
function directly on `ProgramError` that allows us to get the error
message for a particular error type.

Also, clarify the deprecation warning on `DecodeError`.

BREAKING CHANGE: the `ToStr` trait requires fewer bounds
@joncinque joncinque merged commit c0a692d into anza-xyz:master Jun 9, 2025
24 checks passed
@joncinque joncinque deleted the relaxtostr branch June 9, 2025 11:21
febo pushed a commit to febo/solana-sdk that referenced this pull request Sep 21, 2025
#### Problem

The `ToStr` trait is a bit difficult to use, forcing a lot of redundant
uses of types, when programs will just want to call
`err.to_str::<MyError>()`.

#### Summary of changes

Simplify the trait to not require anything, then add a generic `to_str`
function directly on `ProgramError` that allows us to get the error
message for a particular error type.

Also, clarify the deprecation warning on `DecodeError`.

BREAKING CHANGE: the `ToStr` trait requires fewer bounds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking PR contains breaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants