Skip to content

Commit

Permalink
feat(corelib): Into<T, Option<T>>
Browse files Browse the repository at this point in the history
  • Loading branch information
cairolover committed Feb 11, 2025
1 parent b7eea8f commit 4e0cd0c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions corelib/src/option.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,21 @@ pub impl OptionTraitImpl<T> of OptionTrait<T> {
}
}

impl TIntoOption<T> of Into<T, Option<T>> {
/// Moves `self` into a new [`Some`].
///
/// # Examples
///
/// ```
/// let o: Option<u8> = 67_u8.into()
/// assert_eq!(Some(67), o);
/// ```
#[inline]
fn into(self: T) -> Option<T> {
Some(self)
}
}


/// An iterator over the value in the [`Some`] variant of an [`Option`].
///
Expand Down
6 changes: 6 additions & 0 deletions corelib/src/test/option_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,9 @@ fn test_option_flatten() {
assert_eq!(Some(Some(6)), x.flatten());
assert_eq!(Some(6), x.flatten().flatten());
}

#[test]
fn test_option_into() {
let o: Option<u8> = 67_u8.into();
assert_eq!(Some(67), o);
}

0 comments on commit 4e0cd0c

Please sign in to comment.