rust mopa2

mopa = 0.2

python;gutter:true; use mopa; use std::fmt::Debug; use std::fmt::Display; use std::any::TypeId;</p> <p>fn is_string(_s: &T) -> bool { TypeId::of::() == TypeId::of::() }</p> <p>fn is_int(_s: &T) -> bool { TypeId::of::() == TypeId::of::() }</p> <p>fn is_float(_s: &T) -> bool { TypeId::of::() == TypeId::of::() }</p> <p>fn is_str(_s: &T) -> bool { TypeId::of::() == TypeId::of::() }</p> <p>trait N: mopa::Any+Debug+Display{}</p> <p>impl N for i64 {} impl N for f64 {} impl N for String {} impl N for &'static str {}</p> <p>fn dosm(c: impl N){ 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"); } }</p> <p>fn main() { let a = String::from("hello"); let a1 = "A"; dosm(a1); }

Original: https://www.cnblogs.com/pythonClub/p/16518403.html
Author: CrossPython
Title: rust mopa2

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/15788/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

发表回复

登录后才能评论
免费咨询
免费咨询
扫码关注
扫码关注
联系站长

站长Johngo!

大数据和算法重度研究者!

持续产出大数据、算法、LeetCode干货,以及业界好资源!

2022012703491714

微信来撩,免费咨询:xiaozhu_tec

分享本页
返回顶部