Skip to content

Commit

Permalink
write_to
Browse files Browse the repository at this point in the history
  • Loading branch information
cavemanloverboy committed Dec 13, 2023
1 parent 4c0af6d commit 26f7fda
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lang/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,18 @@ pub trait InstructionData: Discriminator + AnchorSerialize {
d.append(&mut self.try_to_vec().expect("Should always serialize"));
d
}
/// Clears `vec` and writes instruction data to it
///
/// We use a Vec<u8> here because of the additional flexibility
fn write_to(&self, mut vec: &mut Vec<u8>) {
// Clear vector
vec.clear();

// Write discriminator and then Self
borsh::to_writer(&mut vec, &Self::DISCRIMINATOR)
.expect("Discriminator is infallibly serializable");
borsh::to_writer(vec, &self).expect("InstructionData should be infallibly serializable");
}
}

/// An event that can be emitted via a Solana log. See [`emit!`](crate::prelude::emit) for an example.
Expand Down

0 comments on commit 26f7fda

Please sign in to comment.