Load from JSON string.
(json: &str)
| 101 | impl GuardRailConfig { |
| 102 | /// Load from JSON string. |
| 103 | pub fn new(json: &str) -> Result<Self, String> { |
| 104 | let c_str = CString::new(json).map_err(|e| e.to_string())?; |
| 105 | let handle = unsafe { guardrail_config_from_json(c_str.as_ptr(), c_str.as_bytes().len()) }; |
| 106 | if handle.is_null() { |
| 107 | return Err("GuardRail config from_json failed".into()); |
| 108 | } |
| 109 | Ok(Self { |
| 110 | inner: Arc::new(GuardRailConfigInner { handle }), |
| 111 | }) |
| 112 | } |
| 113 | |
| 114 | /// Load from file. |
| 115 | pub fn from_file(path: &Path) -> Result<Self, String> { |