]> saetta.ns0.it Git - rust/zakgrid/commitdiff
Added user_data in to_call callback.
authorAndrea Zagli <azagli@libero.it>
Sat, 18 Nov 2023 09:04:10 +0000 (10:04 +0100)
committerAndrea Zagli <azagli@libero.it>
Sat, 18 Nov 2023 09:04:10 +0000 (10:04 +0100)
src/lib.rs

index b1a8a17d626cbbf6b28d5e956446806f4295d17c..6019b297be5e52a26785efaf4b65d42781fbe6bb 100644 (file)
@@ -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<Box<dyn Any>>) -> String;
 
 #[derive(Copy, Clone, Serialize)]
 pub enum Align {
@@ -17,6 +19,7 @@ pub struct Column {
        align: Align,
        hidden: bool,
        to_call: Option<ToCall>,
+       user_data: Option<Box<dyn Any>>,
 }
 
 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<ToCall>) {
+       pub fn set_to_call(&mut self, to_call: Option<ToCall>, user_data: Option<Box<dyn Any>>) {
                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());
                                                        }
                                                }