style: code style
This commit is contained in:
@@ -19,23 +19,21 @@ use abi_stable::{
|
||||
external_types::{
|
||||
crossbeam_channel::RSender,
|
||||
},
|
||||
std_types::{RBox, RCow, RVec, RStr, RString,RResult, ROption, ROk,RSome},
|
||||
std_types::{RBox, RCow, RVec, RStr, RString, RResult, ROption, ROk, RSome},
|
||||
};
|
||||
|
||||
use serde::{Serialize,Deserialize};
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
mod commands;
|
||||
mod error;
|
||||
mod which_plugin;
|
||||
mod vec_from_map;
|
||||
pub mod utils;
|
||||
|
||||
pub mod utils;
|
||||
|
||||
pub use self::{
|
||||
commands::{
|
||||
BasicCommand,BasicRetVal,CommandDescription,CommandTrait,WhichVariant,AsyncCommand,
|
||||
BasicCommand, BasicRetVal, CommandDescription, CommandTrait, WhichVariant, AsyncCommand,
|
||||
},
|
||||
error::{Error,Unsupported},
|
||||
error::{Error, Unsupported},
|
||||
which_plugin::WhichPlugin,
|
||||
vec_from_map::VecFromMap,
|
||||
};
|
||||
@@ -48,8 +46,8 @@ pub use self::{
|
||||
The identifier for a plugin.
|
||||
*/
|
||||
#[repr(C)]
|
||||
#[derive(Debug,Clone,PartialEq,Eq,StableAbi,Serialize,Deserialize)]
|
||||
pub struct PluginId{
|
||||
#[derive(Debug, Clone, PartialEq, Eq, StableAbi, Serialize, Deserialize)]
|
||||
pub struct PluginId {
|
||||
pub named:RCow<'static,str>,
|
||||
/// The number of the instance of this Plugin.
|
||||
pub instance:u64,
|
||||
@@ -58,8 +56,8 @@ pub struct PluginId{
|
||||
|
||||
/// Describes whether a boxed error is a command or a return value.
|
||||
#[repr(u8)]
|
||||
#[derive(Debug,Clone,PartialEq,Eq,StableAbi,Serialize,Deserialize)]
|
||||
pub enum WhichCommandRet{
|
||||
#[derive(Debug, Clone, PartialEq, Eq, StableAbi, Serialize, Deserialize)]
|
||||
pub enum WhichCommandRet {
|
||||
Command,
|
||||
Return,
|
||||
}
|
||||
@@ -67,21 +65,21 @@ pub enum WhichCommandRet{
|
||||
|
||||
/// The response from having called `ApplicationMut::send_command_to_plugin` ealier.
|
||||
#[repr(C)]
|
||||
#[derive(Debug,Clone,PartialEq,Eq,StableAbi)]
|
||||
pub struct PluginResponse<'a>{
|
||||
#[derive(Debug, Clone, PartialEq, Eq, StableAbi)]
|
||||
pub struct PluginResponse<'a> {
|
||||
/// The id of the plugin that is responding.
|
||||
pub plugin_id:PluginId,
|
||||
/// The response from the plugin
|
||||
pub response:RCow<'a,str>,
|
||||
pub response:RCow<'a, str>,
|
||||
}
|
||||
|
||||
|
||||
impl<'a> PluginResponse<'a>{
|
||||
pub fn owned_response(plugin_id:PluginId,response:RString)->Self{
|
||||
Self{plugin_id,response:response.into()}
|
||||
impl<'a> PluginResponse<'a> {
|
||||
pub fn owned_response(plugin_id: PluginId, response: RString) -> Self {
|
||||
Self{plugin_id, response: response.into()}
|
||||
}
|
||||
pub fn borrowed_response(plugin_id:PluginId,response:RStr<'a>)->Self{
|
||||
Self{plugin_id,response:response.into()}
|
||||
pub fn borrowed_response(plugin_id: PluginId, response: RStr<'a>) -> Self {
|
||||
Self{plugin_id, response: response.into()}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +88,7 @@ impl<'a> PluginResponse<'a>{
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
pub type PluginType=Plugin_TO<'static,RBox<()>>;
|
||||
pub type PluginType=Plugin_TO<'static, RBox<()>>;
|
||||
|
||||
|
||||
/**
|
||||
@@ -107,7 +105,7 @@ pub trait Plugin {
|
||||
&mut self,
|
||||
command: RStr<'_>,
|
||||
app:ApplicationMut<'_>,
|
||||
)->RResult<RString,Error>;
|
||||
) -> RResult<RString, Error>;
|
||||
|
||||
/// Handles a response from another Plugin,
|
||||
/// from having called `ApplicationMut::send_command_to_plugin` ealier.
|
||||
@@ -115,15 +113,15 @@ pub trait Plugin {
|
||||
&mut self,
|
||||
response:PluginResponse<'a>,
|
||||
_app:ApplicationMut<'_>,
|
||||
)->RResult<ROption<PluginResponse<'a>>,Error>{
|
||||
) -> RResult<ROption<PluginResponse<'a>>, Error> {
|
||||
ROk(RSome(response))
|
||||
}
|
||||
|
||||
/// Gets the PluginId that was passed to this plugin in its constructor.
|
||||
fn plugin_id(&self)->&PluginId;
|
||||
fn plugin_id(&self) -> &PluginId;
|
||||
|
||||
/// Gets a description of all commands from this Plugin.
|
||||
fn list_commands(&self)->RVec<CommandDescription>;
|
||||
fn list_commands(&self) -> RVec<CommandDescription>;
|
||||
|
||||
/*
|
||||
Closes the plugin,
|
||||
@@ -144,7 +142,7 @@ bumps its "major" version,
|
||||
at which point it would be moved to the last method at the time.
|
||||
*/
|
||||
#[sabi(last_prefix_field)]
|
||||
fn close(self,app:ApplicationMut<'_>);
|
||||
fn close(self, app:ApplicationMut<'_>);
|
||||
}
|
||||
|
||||
|
||||
@@ -174,7 +172,7 @@ at which point it would be moved to the last field at the time.
|
||||
|
||||
*/
|
||||
#[sabi(last_prefix_field)]
|
||||
pub new: extern "C" fn(RSender<AsyncCommand>,PluginId) -> RResult<PluginType,Error>,
|
||||
pub new: extern "C" fn(RSender<AsyncCommand>, PluginId) -> RResult<PluginType, Error>,
|
||||
}
|
||||
|
||||
|
||||
@@ -191,7 +189,7 @@ impl RootModule for PluginMod_Ref {
|
||||
|
||||
|
||||
/// A mutable reference to the application implementation.
|
||||
pub type ApplicationMut<'a>=Application_TO<'a,&'a mut ()>;
|
||||
pub type ApplicationMut<'a> = Application_TO<'a, &'a mut ()>;
|
||||
|
||||
|
||||
#[sabi_trait]
|
||||
@@ -204,10 +202,10 @@ pub trait Application{
|
||||
/// Returns an `Error::InvalidPlugin` if `which_plugin` is invalid.
|
||||
fn send_command_to_plugin(
|
||||
&mut self,
|
||||
from:&PluginId,
|
||||
which_plugin:WhichPlugin,
|
||||
command:RString,
|
||||
)->RResult<(),Error>;
|
||||
from: &PluginId,
|
||||
which_plugin: WhichPlugin,
|
||||
command: RString,
|
||||
) -> RResult<(), Error>;
|
||||
|
||||
/**
|
||||
Gets the `PluginId`s of the plugins specified by `which_plugin`.
|
||||
@@ -224,11 +222,11 @@ at which point it would be moved to the last method at the time.
|
||||
|
||||
*/
|
||||
#[sabi(last_prefix_field)]
|
||||
fn get_plugin_id(&self,which_plugin:WhichPlugin)->RResult<RVec<PluginId>,Error>;
|
||||
fn get_plugin_id(&self, which_plugin:WhichPlugin) -> RResult<RVec<PluginId>, Error>;
|
||||
|
||||
/// Gets the sender end of a channel to send commands to the application/other plugins.
|
||||
fn sender(&self)->RSender<AsyncCommand>;
|
||||
fn sender(&self) -> RSender<AsyncCommand>;
|
||||
|
||||
/// Gets the PluginId of all loaded plugins
|
||||
fn loaded_plugins(&self)->RVec<PluginId>;
|
||||
fn loaded_plugins(&self) -> RVec<PluginId>;
|
||||
}
|
||||
Reference in New Issue
Block a user