subrpc_core/
endpoint.rs

1use crate::{empty_string_array, EndpointStats, EndpointUrl};
2use serde::{Deserialize, Serialize};
3
4#[allow(clippy::derived_hash_with_manual_eq)]
5#[derive(Debug, Hash, Deserialize, Serialize, Clone)]
6pub struct Endpoint {
7	/// Name of the endpoint
8	pub name: String,
9
10	/// Optional labels
11	#[serde(default = "empty_string_array")]
12	pub labels: Vec<String>,
13
14	/// Optional aliases
15	#[serde(default = "empty_string_array")]
16	pub aliases: Vec<String>,
17
18	/// Endpoint URL
19	pub url: EndpointUrl,
20
21	#[serde(default)]
22	pub stats: EndpointStats,
23}
24
25impl PartialEq for Endpoint {
26	fn eq(&self, other: &Self) -> bool {
27		self.name == other.name && self.labels == other.labels && self.url == other.url
28	}
29}
30
31impl Eq for Endpoint {}
32
33impl Endpoint {
34	pub fn new(name: &str, url: &str, labels: Vec<String>, aliases: Vec<String>) -> Self {
35		Self {
36			name: name.to_string(),
37			url: EndpointUrl::try_from(url).unwrap(),
38			labels,
39			aliases,
40			stats: EndpointStats::default(),
41		}
42	}
43}