style: code style

This commit is contained in:
2020-12-27 14:51:24 +08:00
parent 8d34b85a9c
commit cc10c8effd
4 changed files with 436 additions and 84 deletions

View File

@@ -1,4 +1,4 @@
use crate::{PluginId,WhichPlugin};
use crate::{PluginId, WhichPlugin};
use std::fmt;
use serde::{
@@ -11,8 +11,8 @@ use abi_stable::{StableAbi, std_types::*};
// This is intentionally not `#[derive(StableAbi)]`,
// since it can be extended in minor versions of the interface.
// I has to be serialized to pass it through ffi.
#[derive(Debug,Clone,PartialEq,Eq,Serialize,Deserialize)]
pub enum BasicCommand{
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum BasicCommand {
GetCommands,
}
@@ -21,8 +21,8 @@ pub enum BasicCommand{
// This is intentionally not `#[derive(StableAbi)]`,
// since it can be extended in minor versions of the interface.
// I has to be serialized to pass it through ffi.
#[derive(Debug,Clone,PartialEq,Eq,Serialize,Deserialize)]
pub enum BasicRetVal{
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum BasicRetVal {
GetCommands(RVec<CommandDescription>),
}
@@ -30,17 +30,17 @@ pub enum BasicRetVal{
// This is intentionally not `#[derive(StableAbi)]`,
// since it can be extended in minor versions of the interface.
// I has to be serialized to pass it through ffi.
#[derive(Debug,Clone,PartialEq,Eq,Serialize,Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CommandUnion<T>{
pub enum CommandUnion<T> {
ForPlugin(T),
Basic(BasicCommand),
}
#[derive(Debug,Clone,PartialEq,Eq,Serialize,Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ReturnValUnion<T>{
pub enum ReturnValUnion<T> {
ForPlugin(T),
Basic(BasicRetVal),
}
@@ -51,15 +51,15 @@ pub enum ReturnValUnion<T>{
/// A partially deserialize command,that only deserialized its variant.
#[derive(Debug,Clone)]
pub struct WhichVariant{
#[derive(Debug, Clone)]
pub struct WhichVariant {
pub variant:RString,
}
struct WhichVariantVisitor;
impl<'de> Visitor<'de> for WhichVariantVisitor{
impl<'de> Visitor<'de> for WhichVariantVisitor {
type Value = WhichVariant;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
@@ -108,33 +108,33 @@ impl<'de> Deserialize<'de> for WhichVariant{
/// Denotes this as a command type.
pub trait CommandTrait:Serialize{
pub trait CommandTrait:Serialize {
type Returns:DeserializeOwned;
}
impl CommandTrait for BasicCommand{
type Returns=BasicRetVal;
impl CommandTrait for BasicCommand {
type Returns = BasicRetVal;
}
/// Describes a command.
#[repr(C)]
#[derive(Debug,Clone,PartialEq,Eq,Serialize,Deserialize,StableAbi)]
pub struct CommandDescription{
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, StableAbi)]
pub struct CommandDescription {
/// A description of what this command does.
pub name:RCow<'static,str>,
pub name:RCow<'static, str>,
/// A description of what this command does,
/// optionally with a description of the command format.
pub description:RCow<'static,str>,
pub description:RCow<'static, str>,
}
impl CommandDescription{
impl CommandDescription {
pub fn from_literals(
name:&'static str,
description:&'static str,
)->Self{
CommandDescription{
) -> Self {
CommandDescription {
name:name.into(),
description:description.into(),
}
@@ -146,8 +146,8 @@ impl CommandDescription{
#[repr(C)]
#[derive(Debug,Clone,PartialEq,Eq,StableAbi)]
pub struct AsyncCommand{
#[derive(Debug, Clone, PartialEq, Eq, StableAbi)]
pub struct AsyncCommand {
pub from:PluginId,
pub which_plugin:WhichPlugin,
pub command:RString,