-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ae351d
commit 1fdd959
Showing
17 changed files
with
259 additions
and
109 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use { | ||
proc_macro2::Ident, | ||
syn::{ | ||
parse::{Parse, ParseStream}, | ||
token::Comma, | ||
LitBool, Token, | ||
}, | ||
}; | ||
|
||
/// Possible arguments to the `#[spl_program_error]` attribute | ||
pub struct SplProgramErrorArgs { | ||
/// Whether to hash the error codes using `solana_program::hash` | ||
/// or to use the default error code assigned by `num_traits`. | ||
pub hash_error_codes: bool, | ||
} | ||
|
||
impl Parse for SplProgramErrorArgs { | ||
fn parse(input: ParseStream) -> syn::Result<Self> { | ||
if input.is_empty() { | ||
return Ok(Self { | ||
hash_error_codes: false, | ||
}); | ||
} | ||
match SplProgramErrorArgParser::parse(input)? { | ||
SplProgramErrorArgParser::HashErrorCodes { value, .. } => Ok(Self { | ||
hash_error_codes: value.value, | ||
}), | ||
} | ||
} | ||
} | ||
|
||
/// Parser for args to the `#[spl_program_error]` attribute | ||
/// ie. `#[spl_program_error(hash_error_codes = true)]` | ||
enum SplProgramErrorArgParser { | ||
HashErrorCodes { | ||
_ident: Ident, | ||
_equals_sign: Token![=], | ||
value: LitBool, | ||
_comma: Option<Comma>, | ||
}, | ||
} | ||
|
||
impl Parse for SplProgramErrorArgParser { | ||
fn parse(input: ParseStream) -> syn::Result<Self> { | ||
let _ident = input.parse::<Ident>()?; | ||
let _equals_sign = input.parse::<Token![=]>()?; | ||
let value = input.parse::<LitBool>()?; | ||
let _comma: Option<Comma> = input.parse().unwrap_or(None); | ||
Ok(Self::HashErrorCodes { | ||
_ident, | ||
_equals_sign, | ||
value, | ||
_comma, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
//! Tests `#[derive(DecodeError)]` | ||
//! | ||
|
||
use spl_program_error::*; | ||
|
||
/// Example error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
//! Tests `#[derive(IntoProgramError)]` | ||
//! | ||
|
||
use spl_program_error::*; | ||
|
||
/// Example error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
//! Tests `#[derive(PrintProgramError)]` | ||
//! | ||
|
||
use spl_program_error::*; | ||
|
||
/// Example error | ||
|
Oops, something went wrong.