pub struct Registry<State = Invalid> { /* private fields */ }Expand description
A collection of signals with their computational dependencies.
The Registry struct serves as the central data structure for managing asset signals.
It stores signal definitions indexed by their unique IDs and provides methods for
accessing and validating them.
The State type parameter indicates whether the registry has been validated:
Registry<Invalid>- A registry that has not been validated or has failed validationRegistry<Valid>- A registry that has been successfully validated
§Examples
Creating and validating a registry:
use bothan_lib::registry::{Registry, Invalid, Valid};
use serde_json::json;
// Create a registry from JSON
let json_data = json!({
"BTC-USD": {
"sources": [
{
"source_id": "binance",
"id": "btcusdt",
"routes": []
}
],
"processor": {
"function": "median",
"params": {
"min_source_count": 1
}
},
"post_processors": []
}
});
let registry_json = serde_json::to_string(&json_data).unwrap();
let registry: Registry<Invalid> = serde_json::from_str(®istry_json).unwrap();
// Validate the registry
let valid_registry: Registry<Valid> = registry.validate().unwrap();
// Use the validated registry
assert!(valid_registry.contains("BTC-USD"));Implementations§
Source§impl Registry<Invalid>
impl Registry<Invalid>
Sourcepub fn validate(self) -> Result<Registry<Valid>, ValidationError>
pub fn validate(self) -> Result<Registry<Valid>, ValidationError>
Validates the registry, ensuring all dependencies exist and there are no cycles.
This method performs a thorough validation of the registry, checking that:
- All signal dependencies (referenced by signal IDs) exist in the registry
- There are no circular dependencies between signals
If validation is successful, the registry is converted to the Valid state.
If validation fails, an error is returned explaining the validation failure.
§Returns
Ok(Registry<Valid>)if validation is successfulErr(ValidationError)if validation fails
§Examples
use bothan_lib::registry::{Registry, ValidationError};
use serde_json::json;
// Create a valid registry
let valid_json = json!({
"USDT-USD": {
"sources": [
{
"source_id": "coingecko",
"id": "tether",
"routes": []
}
],
"processor": {
"function": "median",
"params": {
"min_source_count": 1
}
},
"post_processors": []
}
});
let valid_registry: Registry = serde_json::from_value(valid_json).unwrap();
assert!(valid_registry.validate().is_ok());
// Create an invalid registry with a missing dependency
let invalid_json = json!({
"BTC-USD": {
"sources": [
{
"source_id": "binance",
"id": "btcusdt",
"routes": [
{
"signal_id": "USDT-USD", // This dependency doesn't exist
"operation": "*"
}
]
}
],
"processor": {
"function": "median",
"params": {
"min_source_count": 1
}
},
"post_processors": []
}
});
let invalid_registry: Registry = serde_json::from_value(invalid_json).unwrap();
assert!(invalid_registry.validate().is_err());Source§impl<T> Registry<T>
impl<T> Registry<T>
Sourcepub fn contains(&self, signal_id: &str) -> bool
pub fn contains(&self, signal_id: &str) -> bool
Returns true if the registry contains the given signal id.
This method checks whether a signal with the specified ID exists in the registry.
§Returns
trueif the signal exists in the registryfalseif the signal does not exist
Sourcepub fn signal_ids(&self) -> impl Iterator<Item = &String>
pub fn signal_ids(&self) -> impl Iterator<Item = &String>
An iterator visiting all signal ids in the registry in arbitrary order.
This method returns an iterator over all signal IDs in the registry. The order of iteration is not specified and may vary between calls.
§Returns
An iterator yielding references to signal IDs
Sourcepub fn iter(&self) -> impl Iterator<Item = (&String, &Signal)>
pub fn iter(&self) -> impl Iterator<Item = (&String, &Signal)>
An iterator visiting all the signal ids and their signals in the registry in arbitrary order.
This method returns an iterator over all signal IDs and their corresponding signals in the registry. The order of iteration is not specified and may vary between calls.
§Returns
An iterator yielding pairs of references to signal IDs and their signals
Trait Implementations§
Source§impl<Context> Decode<Context> for Registry<Invalid>
impl<Context> Decode<Context> for Registry<Invalid>
Source§fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>
fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError>
Decodes a registry from binary serialization.
This implementation enables efficient binary deserialization of the registry
using the bincode crate. It decodes the inner map of signals and creates
an invalid registry that must be validated before use.
§Errors
Returns a DecodeError if decoding fails
Source§impl<'de, State> Deserialize<'de> for Registry<State>
impl<'de, State> Deserialize<'de> for Registry<State>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<State> Encode for Registry<State>
impl<State> Encode for Registry<State>
Source§fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>
fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError>
Encodes the registry for binary serialization.
This implementation enables efficient binary serialization of the registry
using the bincode crate. It encodes the inner map of signals.
§Errors
Returns an EncodeError if encoding fails
impl<State> StructuralPartialEq for Registry<State>
Auto Trait Implementations§
impl<State> Freeze for Registry<State>
impl<State> RefUnwindSafe for Registry<State>where
State: RefUnwindSafe,
impl<State> Send for Registry<State>where
State: Send,
impl<State> Sync for Registry<State>where
State: Sync,
impl<State> Unpin for Registry<State>where
State: Unpin,
impl<State> UnwindSafe for Registry<State>where
State: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request