chrome_native/
lib.rs

1use serde::{Deserialize, Serialize};
2use std::{any::Any, error::Error};
3
4pub const ERRORCODE_OK: i32 = 0;
5pub const ERRORCODE_FAIL: i32 = -1;
6pub trait Plugin: Any + Send + Sync {
7    fn handle_command(&self, command: String) -> Result<String, Box<dyn Error>>;
8}
9
10#[derive(thiserror::Error, Debug)]
11pub enum ChromeNativeErrors {
12    #[error("Not the right type")]
13    NotRightType,
14}
15
16#[cfg(feature = "serde")]
17pub fn parse_data<'a, T>(data: &'a str) -> Result<T, Box<impl Error>>
18where
19    T: Serialize + Deserialize<'a>,
20{
21    serde_json::from_str::<T>(data).map_err(|_| Box::new(ChromeNativeErrors::NotRightType))
22}
23
24#[cfg(feature = "macros")]
25#[allow(unused_imports)]
26#[macro_use]
27extern crate chrome_native_macros;
28#[cfg(feature = "macros")]
29pub use chrome_native_macros::*;