Skip to content

Instantly share code, notes, and snippets.

@st3fan
Created September 24, 2022 19:54
Embed
What would you like to do?
#[cfg(test)]
mod tests {
use std::convert::TryInto;
use std::num::TryFromIntError;
#[test]
fn it_works() {
let a = 1i16;
let b: Result<i8, TryFromIntError> = a.try_into();
assert!(b.is_ok());
}
#[test]
fn overflow() {
let a = 256i16;
let b: Result<i8, TryFromIntError> = a.try_into();
assert!(b.is_err());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment