Skip to content

Instantly share code, notes, and snippets.

@st3fan
Created September 24, 2022 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save st3fan/2b665344ab3c3e601fb183cd6379bfc1 to your computer and use it in GitHub Desktop.
Save st3fan/2b665344ab3c3e601fb183cd6379bfc1 to your computer and use it in GitHub Desktop.
#[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