style: code style
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
use crate::{commands::CommandDescription,WhichPlugin,WhichCommandRet};
|
||||
use crate::{commands::CommandDescription, WhichPlugin, WhichCommandRet};
|
||||
|
||||
use abi_stable::{StableAbi, std_types::{RBoxError,RBox,RString,RVec}};
|
||||
use std::{error::Error as ErrorTrait, fmt::{self,Display}};
|
||||
use abi_stable::{StableAbi, std_types::{RBoxError, RBox, RString, RVec}};
|
||||
use std::{error::Error as ErrorTrait, fmt::{self, Display}};
|
||||
use core_extensions::strings::StringExt;
|
||||
|
||||
#[repr(u8)]
|
||||
#[derive(Debug,StableAbi)]
|
||||
#[derive(Debug, StableAbi)]
|
||||
pub enum Error{
|
||||
/// An error produced by `serde_json::to_string`.
|
||||
Serialize(RBoxError,WhichCommandRet),
|
||||
@@ -27,8 +27,8 @@ pub enum Error{
|
||||
|
||||
/// Represents a command or return value that wasn't supported.
|
||||
#[repr(C)]
|
||||
#[derive(Debug,StableAbi)]
|
||||
pub struct Unsupported{
|
||||
#[derive(Debug, StableAbi)]
|
||||
pub struct Unsupported {
|
||||
/// The name of the plugin for which the command/return value wasn't supported.
|
||||
pub plugin_name:RString,
|
||||
/// The command/return value that wasn't supported.
|
||||
@@ -40,33 +40,33 @@ pub struct Unsupported{
|
||||
}
|
||||
|
||||
|
||||
impl Error{
|
||||
pub fn unsupported_command(what:Unsupported)->Self{
|
||||
impl Error {
|
||||
pub fn unsupported_command(what:Unsupported) -> Self {
|
||||
Error::UnsupportedCommand(RBox::new(what))
|
||||
}
|
||||
pub fn unsupported_return_value(what:Unsupported)->Self{
|
||||
pub fn unsupported_return_value(what:Unsupported) -> Self {
|
||||
Error::UnsupportedReturnValue(RBox::new(what))
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Error{
|
||||
fn fmt(&self,f:&mut fmt::Formatter<'_>)->fmt::Result {
|
||||
impl Display for Error {
|
||||
fn fmt(&self, f:&mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Error::Serialize(e,which)=>{
|
||||
let which=match which {
|
||||
WhichCommandRet::Command=>"command",
|
||||
WhichCommandRet::Return=>"return value",
|
||||
Error::Serialize(e, which) => {
|
||||
let which = match which {
|
||||
WhichCommandRet::Command => "command",
|
||||
WhichCommandRet::Return => "return value",
|
||||
};
|
||||
writeln!(f,"Error happened while serializing the {}:\n{}\n",which,e)
|
||||
}
|
||||
Error::Deserialize(e,which)=>{
|
||||
let which=match which {
|
||||
WhichCommandRet::Command=>"command",
|
||||
WhichCommandRet::Return=>"return value",
|
||||
Error::Deserialize(e, which) => {
|
||||
let which = match which {
|
||||
WhichCommandRet::Command => "command",
|
||||
WhichCommandRet::Return => "return value",
|
||||
};
|
||||
writeln!(f,"Error happened while deserializing {}:\n{}\n",which,e)
|
||||
writeln!(f,"Error happened while deserializing {}:\n{}\n", which, e)
|
||||
}
|
||||
Error::UnsupportedCommand(v)=>{
|
||||
Error::UnsupportedCommand(v) => {
|
||||
writeln!(
|
||||
f,
|
||||
"Plugin '{}' ooes not support this command:\n\
|
||||
@@ -77,7 +77,6 @@ impl Display for Error{
|
||||
v.plugin_name,
|
||||
v.command_name,
|
||||
v.error,
|
||||
|
||||
)?;
|
||||
|
||||
for supported in &v.supported_commands {
|
||||
@@ -94,7 +93,7 @@ impl Display for Error{
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Error::UnsupportedReturnValue(v)=>
|
||||
Error::UnsupportedReturnValue(v) =>
|
||||
writeln!(
|
||||
f,
|
||||
"Unrecognized return value from '{}',named:\n\
|
||||
@@ -105,14 +104,14 @@ impl Display for Error{
|
||||
v.command_name,
|
||||
v.error,
|
||||
),
|
||||
Error::InvalidPlugin(wc)=>
|
||||
Error::InvalidPlugin(wc) =>
|
||||
writeln!(
|
||||
f,
|
||||
"Attempted to access a nonexistent plugin with the WhichPlugin:\n\t{:?}\n",
|
||||
wc
|
||||
),
|
||||
Error::Custom(e)=>Display::fmt(e,f),
|
||||
Error::Many(list)=>{
|
||||
Error::Custom(e) => Display::fmt(e, f),
|
||||
Error::Many(list) => {
|
||||
for e in list {
|
||||
writeln!(f,"{}",e)?;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user