用法
pub fn is<T>(&self) -> bool where T:Any,
如果装箱类型与 T
相同,则返回 true
。
例子
use std::any::Any;
fn is_string(s:&dyn Any) {
if s.is::<String>() {
println!("It's a string!");
} else {
println!("Not a string...");
}
}
is_string(&0);
is_string(&"cookie monster".to_string());
相关用法
- Rust std::any::Any.downcast_mut用法及代码示例
- Rust std::any::Any.downcast_ref用法及代码示例
- Rust std::any::Any.type_id用法及代码示例
- Rust std::any::type_name用法及代码示例
- Rust std::any::type_name_of_val用法及代码示例
- Rust std::any::TypeId.of用法及代码示例
- Rust std::array::try_from_fn用法及代码示例
- Rust std::alloc::GlobalAlloc用法及代码示例
- Rust std::assert用法及代码示例
- Rust std::alloc::Layout.extend用法及代码示例
- Rust std::assert_eq用法及代码示例
- Rust std::alloc::alloc用法及代码示例
- Rust std::ascii::AsciiExt用法及代码示例
- Rust std::array::IntoIter.new用法及代码示例
- Rust std::assert_matches::debug_assert_matches用法及代码示例
- Rust std::ascii::escape_default用法及代码示例
- Rust std::assert_matches::assert_matches用法及代码示例
- Rust std::alloc::System用法及代码示例
- Rust std::assert_ne用法及代码示例
- Rust std::array::from_fn用法及代码示例
注:本文由纯净天空筛选整理自rust-lang.org大神的英文原创作品 std::any::Any.is。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。