test_panic 0.8.0

Utility for test cases with panic.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//! Crate's utility.

use std::any::Any;

/// Converts string like value to string.
pub(crate) fn string_like_to_string(any: &(dyn Any + Send)) -> Option<String> {
    if let Some(x) = any.downcast_ref::<&str>() {
        return Some(x.to_string());
    }

    if let Some(x) = any.downcast_ref::<String>() {
        return Some(x.to_owned());
    }

    None
}