Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::collections::HashMap;
- use std::any::Any;
- fn main() {
- let mut h: HashMap<&str, &Any> = HashMap::new();
- h.insert("width", &321_i32);
- h.insert("msg", &"hello");
- if let Some(v) = h.get("width") {
- match v.downcast_ref::<i32>() {
- Some(v) => {
- println!("width: {}", v);
- },
- None => {
- println!("noop");
- }
- }
- }
- if let Some(v) = h.get("msg") {
- match v.downcast_ref::<&str>() {
- Some(v) => {
- println!("msg: {}", v);
- },
- None => {
- println!("noop");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment