diff --git a/light-base/src/lib.rs b/light-base/src/lib.rs index cdd9c97723..9d2f6ef9e1 100644 --- a/light-base/src/lib.rs +++ b/light-base/src/lib.rs @@ -134,11 +134,26 @@ pub struct AddChainConfig<'a, TChain, TRelays> { } /// Chain registered in a [`Client`]. +/// +/// This type is a simple wrapper around a `usize`. Use the `From for ChainId` and +/// `From for usize` trait implementations to convert back and forth if necessary. // // Implementation detail: corresponds to indices within [`Client::public_api_chains`]. #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct ChainId(usize); +impl From for ChainId { + fn from(id: usize) -> ChainId { + ChainId(id) + } +} + +impl From for usize { + fn from(chain_id: ChainId) -> usize { + chain_id.0 + } +} + /// Holds a list of chains, connections, and JSON-RPC services. pub struct Client { /// Access to the platform capabilities.