Skip to content

Commit

Permalink
Allow converting back and forth between ChainId and usize (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaka authored Apr 18, 2023
1 parent d6bdf0a commit 28d9245
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions light-base/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize> for ChainId` and
/// `From<ChainId> 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<usize> for ChainId {
fn from(id: usize) -> ChainId {
ChainId(id)
}
}

impl From<ChainId> for usize {
fn from(chain_id: ChainId) -> usize {
chain_id.0
}
}

/// Holds a list of chains, connections, and JSON-RPC services.
pub struct Client<TPlat: platform::PlatformRef, TChain = ()> {
/// Access to the platform capabilities.
Expand Down

0 comments on commit 28d9245

Please sign in to comment.