zksync_node_framework/resource/resource_id.rs
1use std::any::TypeId;
2
3/// A unique identifier of a resource.
4///
5/// Internal representation is [`TypeId`], which is a 64-bit hash.
6/// That is sufficient for our purposes, as even when using 2^16 different resources,
7/// the chance of a hash collision occurring is about 1 in 2^32.
8/// This [Stack overflow answer](https://stackoverflow.com/a/62667633) explains how to derive the likelihood.
9#[derive(Debug, Clone, PartialEq, Eq, Hash)]
10pub struct ResourceId(TypeId);
11
12impl ResourceId {
13 pub fn of<T: 'static>() -> Self {
14 Self(TypeId::of::<T>())
15 }
16}