Skip to content

Commit

Permalink
Change custom data type to serde_json::Value
Browse files Browse the repository at this point in the history
Signed-off-by: Piotr Piotrowski <piotr@synadia.com>
  • Loading branch information
piotrpio committed Oct 19, 2023
1 parent 9ee3b42 commit 9016d38
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions async-nats/src/service/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub(crate) struct Inner {
/// Last error that occurred.
pub(crate) last_error: Option<error::Error>,
/// Custom data added by [Config::stats_handler]
pub(crate) data: Option<String>,
pub(crate) data: Option<serde_json::Value>,
/// Queue group to which this endpoint is assigned to.
pub(crate) queue_group: String,
}
Expand Down Expand Up @@ -173,7 +173,7 @@ pub struct Stats {
#[serde(with = "serde_error_string")]
pub last_error: Option<error::Error>,
/// Custom data added by [crate::service::Config::stats_handler]
pub data: Option<String>,
pub data: Option<serde_json::Value>,
/// Queue group to which this endpoint is assigned to.
pub queue_group: String,
}
Expand Down
6 changes: 3 additions & 3 deletions async-nats/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl ServiceBuilder {
/// Handler for custom service statistics.
pub fn stats_handler<F>(mut self, handler: F) -> Self
where
F: FnMut(String, endpoint::Stats) -> String + Send + Sync + 'static,
F: FnMut(String, endpoint::Stats) -> serde_json::Value + Send + Sync + 'static,
{
self.stats_handler = Some(StatsHandler(Box::new(handler)));
self
Expand Down Expand Up @@ -265,7 +265,7 @@ pub trait ServiceExt {
/// let mut service = client
/// .service_builder()
/// .description("some service")
/// .stats_handler(|endpoint, stats| format!("customstats"))
/// .stats_handler(|endpoint, stats| serde_json::json!({ "endpoint": endpoint }))
/// .start("products", "1.0.0")
/// .await?;
///
Expand Down Expand Up @@ -870,7 +870,7 @@ impl EndpointBuilder {
}
}

pub struct StatsHandler(pub Box<dyn FnMut(String, endpoint::Stats) -> String + Send>);
pub struct StatsHandler(pub Box<dyn FnMut(String, endpoint::Stats) -> serde_json::Value + Send>);

impl std::fmt::Debug for StatsHandler {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Expand Down
2 changes: 1 addition & 1 deletion async-nats/tests/service_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ mod service {

let service = client
.service_builder()
.stats_handler(|endpoint, _| format!("custom data for {endpoint}"))
.stats_handler(|endpoint, _| serde_json::json!({ "endpoint": endpoint }))
.description("a cross service")
.start("cross", "1.0.0")
.await
Expand Down

0 comments on commit 9016d38

Please sign in to comment.