rust mopa2
mopa = 0.2
use mopa; use std::fmt::Debug; use std::fmt::Display; use std::any::TypeId; fn is_string<T: ?Sized + mopa::Any>(_s: &T) -> bool { TypeId::of::<String>() == TypeId::of::<T>() } fn is_int<T: ?Sized + mopa::Any>(_s: &T) -> bool { TypeId::of::<i64>() == TypeId::of::<T>() } fn is_float<T: ?Sized + mopa::Any>(_s: &T) -> bool { TypeId::of::<f64>() == TypeId::of::<T>() } fn is_str<T: ?Sized + mopa::Any>(_s: &T) -> bool { TypeId::of::<&str>() == TypeId::of::<T>() } trait N<'a>: mopa::Any+Debug+Display{} impl<'a> N<'a> for i64 {} impl<'a> N<'a> for f64 {} impl<'a> N<'a> for String {} impl N<'static> for &'static str {} fn dosm<'a>(c: impl N<'a>){ println!("{}", c); if is_int(&c){ println!("yes, int"); } if is_float(&c){ println!("float, it is,"); } if is_string(&c){ println!("it is string"); } if is_str(&c){ println!("it is str"); } } fn main() { let a = String::from("hello"); let a1 = "A"; dosm(a1); }