Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit f5997d6

Browse files
authored
pod: Implement Default for PodOption (#7083)
1 parent 8cc0a40 commit f5997d6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

libraries/pod/src/option.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ pub trait Nullable: PartialEq + Pod + Sized {
4343
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
4444
pub struct PodOption<T: Nullable>(T);
4545

46+
impl<T: Nullable> Default for PodOption<T> {
47+
fn default() -> Self {
48+
Self(T::NONE)
49+
}
50+
}
51+
4652
impl<T: Nullable> PodOption<T> {
4753
/// Returns the contained value as an `Option`.
4854
#[inline]
@@ -178,4 +184,10 @@ mod tests {
178184
let err = PodOption::try_from(invalid_option).unwrap_err();
179185
assert_eq!(err, ProgramError::InvalidArgument);
180186
}
187+
188+
#[test]
189+
fn test_default() {
190+
let def = PodOption::<Pubkey>::default();
191+
assert_eq!(def, None.try_into().unwrap());
192+
}
181193
}

0 commit comments

Comments
 (0)