ray_debug/
rayable.rs

1use serde::Serialize;
2use serde_json::{Number, Value};
3
4use crate::helpers;
5use crate::ray_request::RayRequest;
6
7pub trait Rayable {
8    fn into_ray_request(self) -> RayRequest;
9}
10
11impl<T: serde::Serialize> Rayable for &T {
12    fn into_ray_request(self) -> RayRequest {
13        to_html_request(&self)
14    }
15}
16
17impl Rayable for String {
18    fn into_ray_request(self) -> RayRequest {
19        to_html_request(&self)
20    }
21}
22
23impl Rayable for &str {
24    fn into_ray_request(self) -> RayRequest {
25        RayRequest::log(self, None)
26    }
27}
28
29impl Rayable for Value {
30    fn into_ray_request(self) -> RayRequest {
31        to_html_request(&self)
32    }
33}
34
35impl Rayable for Number {
36    fn into_ray_request(self) -> RayRequest {
37        to_html_request(&self)
38    }
39}
40
41impl Rayable for i64 {
42    fn into_ray_request(self) -> RayRequest {
43        to_html_request(&self)
44    }
45}
46
47impl<T: serde::Serialize> Rayable for Vec<T> {
48    fn into_ray_request(self) -> RayRequest {
49        to_html_request(&self)
50    }
51}
52
53fn to_html_request<T: Serialize>(value: &T) -> RayRequest {
54    let json = helpers::get_json(value, false);
55    let serde_value = serde_json::from_str(&json).unwrap();
56
57    RayRequest::html(helpers::value_to_html(&serde_value), None)
58}