How Can I Pattern-Match Items Pulled from a Dashmap?

I am trying to pattern match on an enum when getting an item from my dashmap::DashMap. However, it looks like they have a wrapper type over the Entity when they return the data. How can I pattern match over the items then?

use once_cell::sync::Lazy;
use dashmap::DashMap;

enum Entity {
    Person { name: String },
    Animal { name: String },
}

static ENTITIES: Lazy<DashMap<usize, Entity>> = Lazy::new(|| DashMap::new());

fn main() {
    ENTITIES.insert(
        0,
        Entity::Animal {
            name: "pikachu".into(),
        },
    );
    ENTITIES.insert(
        1,
        Entity::Person {
            name: "trainer mike".into(),
        },
    );

    match ENTITIES.get(&0) {
        Some(Entity::Animal { name }) => { // compile error here
            println!("found animal: {}", name);
        }
        _ => panic!("did not find person"),
    }
}

And the error:

error[E0308]: mismatched types
  --> src\lib.rs:__:__
   |
   |     match ENTITIES.get(&0) {
   |           -------------- this expression has type `Option<dashmap::mapref::one::Ref<'_, usize, Entity>>`
   |         Some(Entity::Animal { name }) => {
   |              ^^^^^^^^^^^^^^^^^^^^^^^ expected struct `dashmap::mapref::one::Ref`, found enum `Entity`
   |
   = note: expected struct `dashmap::mapref::one::Ref<'_, usize, Entity, >`
                found enum `Entity`
3
Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article