From 6487a01b81ddfbcba91af5d023045a186edc2d6a Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sat, 18 Nov 2023 10:04:10 +0100 Subject: [PATCH] Added user_data in to_call callback. --- src/lib.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b1a8a17..6019b29 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,10 @@ +use std::any::Any; + use serde_json::Value; use serde_derive::Serialize; use tera::Tera; -pub type ToCall = fn(row: &serde_json::Value) -> String; +pub type ToCall = fn(row: &serde_json::Value, user_data: &Option>) -> String; #[derive(Copy, Clone, Serialize)] pub enum Align { @@ -17,6 +19,7 @@ pub struct Column { align: Align, hidden: bool, to_call: Option, + user_data: Option>, } impl Column { @@ -27,6 +30,7 @@ impl Column { align: Align::Left, hidden: false, to_call: None, + user_data: None, } } @@ -58,8 +62,9 @@ impl Column { self.hidden } - pub fn set_to_call(&mut self, to_call: Option) { + pub fn set_to_call(&mut self, to_call: Option, user_data: Option>) { self.to_call = to_call; + self.user_data = user_data; } } @@ -154,7 +159,7 @@ impl Grid { match c.to_call { None => context.insert("value", ""), Some(call) => { - let v = (call)(&row); + let v = (call)(&row, &c.user_data); context.insert("value", v.as_str()); } } -- 2.49.0