Skip to main content

graphql_ws_client/client/
conection_id.rs

1use std::num::NonZero;
2
3#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
4/// An opaque identifier for a subscription
5///
6/// Currently this wraps a `NonZero<usize>` though that may be subject to change
7/// in the future - as a result the underlying type is not exposed publically
8pub struct SubscriptionId(NonZero<usize>);
9
10impl SubscriptionId {
11    pub(super) fn new(id: usize) -> Option<Self> {
12        Some(SubscriptionId(NonZero::new(id)?))
13    }
14
15    #[expect(clippy::inherent_to_string)] // Don't want this to be public, which implementing Display would make it.
16    pub(super) fn to_string(self) -> String {
17        self.0.to_string()
18    }
19
20    pub(super) fn from_str(s: &str) -> Option<Self> {
21        SubscriptionId::new(s.parse::<usize>().ok()?)
22    }
23}