Datasets:

Modalities:
Text
Formats:
text
Size:
< 1K
Libraries:
Datasets
License:
PyRs2 / rust /src /pattern_matching.rs
khulnasoft's picture
Upload folder using huggingface_hub
998b6cc verified
raw
history blame contribute delete
597 Bytes
fn describe(x: &dyn std::any::Any) {
match x {
x if x.is::<i32>() => {
if let Some(val) = x.downcast_ref::<i32>() {
match val {
1 => println!("one"),
2 => println!("two"),
_ => println!("an integer"),
}
}
}
x if x.is::<&str>() => {
println!("a string");
}
_ => {
println!("something else");
}
}
}
fn main() {
describe(&1);
describe(&2);
describe(&"hello");
describe(&vec![1, 2, 3]);
}