Skip to content

Commit

Permalink
Update doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
joncinque committed Nov 18, 2024
1 parent a851a31 commit 36402e5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl InterestBearingConfig {
/// The new average rate is the time-weighted average of the current rate
/// and average rate, solving for r such that:
///
/// ```no_run
/// ```text
/// exp(r_1 * t_1) * exp(r_2 * t_2) = exp(r * (t_1 + t_2))
///
/// r_1 * t_1 + r_2 * t_2 = r * (t_1 + t_2)
Expand Down
6 changes: 3 additions & 3 deletions token/program-2022/src/extension/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ fn check_account_type<S: BaseState>(account_type: AccountType) -> Result<(), Pro
/// Account with an extension, even if we add the account type. For example,
/// let's say we have:
///
/// ```no_run
/// ```text
/// Account: 165 bytes... + [2, 0, 3, 0, 100, ....]
/// ^ ^ ^ ^
/// acct type extension length data...
Expand Down Expand Up @@ -1367,8 +1367,8 @@ pub trait Extension {
/// `size_of::<AccountType>() = 1`, `size_of::<ExtensionType>() = 2`,
/// `size_of::<Length>() = 2`.
///
/// ```no_run
/// 355 - 165 - 1 - 2 - 2 = 185
/// ```
/// assert_eq!(355 - 165 - 1 - 2 - 2, 185);
/// ```
#[cfg(test)]
#[repr(C)]
Expand Down
22 changes: 19 additions & 3 deletions token/program-2022/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1951,10 +1951,26 @@ pub fn decode_instruction_type<T: TryFrom<u8>>(input: &[u8]) -> Result<T, Progra
/// instruction type as the first byte. This makes the code concise and safe
/// at the expense of clarity, allowing flows such as:
///
/// ```no_run
/// match decode_instruction_type(input)? {
/// ```
/// use spl_token_2022::instruction::{decode_instruction_data, decode_instruction_type};
/// use num_enum::TryFromPrimitive;
/// use bytemuck::{Pod, Zeroable};
///
/// #[repr(u8)]
/// #[derive(Clone, Copy, TryFromPrimitive)]
/// enum InstructionType {
/// First
/// }
/// #[derive(Pod, Zeroable, Copy, Clone)]
/// #[repr(transparent)]
/// struct FirstData {
/// a: u8,
/// }
/// let input = [0, 1];
/// match decode_instruction_type(&input).unwrap() {
/// InstructionType::First => {
/// let FirstData { ... } = decode_instruction_data(input)?;
/// let FirstData { a } = decode_instruction_data(&input).unwrap();
/// assert_eq!(*a, 1);
/// }
/// }
/// ```
Expand Down

0 comments on commit 36402e5

Please sign in to comment.