Skip to content

Commit

Permalink
clippy: fix warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Vincenzo Palazzo <[email protected]>
  • Loading branch information
vincenzopalazzo committed Mar 24, 2024
1 parent 3dda4c7 commit 12505dc
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 26 deletions.
7 changes: 5 additions & 2 deletions plugin/examples/foo_plugin.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
extern crate clightningrpc_plugin;

use std::io;

use clightningrpc_plugin::types::LogLevel;
use clightningrpc_plugin::{commands::RPCCommand, errors::PluginError, plugin::Plugin};
use serde_json::{json, Value};
Expand Down Expand Up @@ -35,7 +37,7 @@ impl RPCCommand<PluginState> for OnShutdown {
}
}

fn main() {
fn main() -> io::Result<()> {
let plugin = Plugin::<PluginState>::new(PluginState(()), true)
.add_rpc_method(
"hello",
Expand All @@ -56,5 +58,6 @@ fn main() {
json!({})
})
.clone();
plugin.start();
plugin.start()?;
Ok(())
}
2 changes: 1 addition & 1 deletion plugin/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub trait RPCCommand<T: Clone>: RPCCommandClone<T> {
}

/// void call is a generic method that it is used to simulate a callback with a void return type
fn call_void<'c>(&self, _plugin: &mut Plugin<T>, _request: &'c serde_json::Value) {}
fn call_void(&self, _plugin: &mut Plugin<T>, _request: &serde_json::Value) {}
}

// Splitting RPCCommandClone into its own trait allows us to provide a blanket
Expand Down
10 changes: 5 additions & 5 deletions plugin/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ impl<'a, T: 'a + Clone> Plugin<T> {
) -> &mut Self {
let def_val = match opt_type {
"flag" | "bool" => {
def_val.and_then(|val| Some(serde_json::json!(val.parse::<bool>().unwrap())))
def_val.map(|val| serde_json::json!(val.parse::<bool>().unwrap()))
}
"int" => def_val.and_then(|val| Some(serde_json::json!(val.parse::<i64>().unwrap()))),
"string" => def_val.and_then(|val| Some(serde_json::json!(val))),
"int" => def_val.map(|val| serde_json::json!(val.parse::<i64>().unwrap())),
"string" => def_val.map(|val| serde_json::json!(val)),
_ => unreachable!("{opt_type} not supported"),
};
self.option.insert(
Expand Down Expand Up @@ -293,14 +293,14 @@ impl<'a, T: 'a + Clone> Plugin<T> {
request.method,
rpc_response
);
return Some(serde_json::to_string(&rpc_response).unwrap());
Some(serde_json::to_string(&rpc_response).unwrap())
} else {
// in case of the id is None, we are receiving the notification, so the server is not
// interested in the answer.
self.handle_notification(&request.method, request.params);
#[cfg(feature = "log")]
log::info!("notification: {}", request.method);
return None;
None
}
})?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion plugin_macros/src/attr_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn parse_key_values(
trace!(tracer, "removing the `,` tok");
check!(",", stream.advance())?;
}
let value = value.to_string().replace("\"", "");
let value = value.to_string().replace('\"', "");
trace!(tracer, "key {key} = value {value}");
hash_map.insert(key.to_string(), value.to_string());
trace!(tracer, "map is {:?}", hash_map);
Expand Down
17 changes: 4 additions & 13 deletions plugin_macros/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use kproc_parser::proc_macro::{TokenStream, TokenTree};
use kproc_parser::{build_error, check, trace};

#[derive(Debug)]
#[derive(Default)]
pub struct PluginDeclaration {
pub state: Option<String>,
pub dynamic: Option<TokenTree>,
Expand All @@ -27,7 +28,7 @@ impl std::fmt::Display for PluginDeclaration {
.map_or(String::from("false"), |val| val.to_string())
)?;
if let Some(ref inner) = self.notificatios {
let mut inner = KTokenStream::new(&inner);
let mut inner = KTokenStream::new(inner);
while !inner.is_end() {
let notification = inner.advance();
writeln!(f, "let call = {}();", notification)?;
Expand All @@ -42,7 +43,7 @@ impl std::fmt::Display for PluginDeclaration {
}
}
if let Some(ref inner) = self.rpc_methods {
let mut inner = KTokenStream::new(&inner);
let mut inner = KTokenStream::new(inner);
while !inner.is_end() {
let rpc = inner.advance();
writeln!(f, "let call = {}();", rpc)?;
Expand All @@ -58,17 +59,7 @@ impl std::fmt::Display for PluginDeclaration {
}
}

impl Default for PluginDeclaration {
fn default() -> Self {
Self {
state: None,
dynamic: None,
notificatios: None,
hooks: None,
rpc_methods: None,
}
}
}


/// proc macro syntax is something like this
///
Expand Down
8 changes: 4 additions & 4 deletions tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ pub mod fixtures {
pub fn lightningd() -> cln::Node {
init();
let pwd = std::env::var("PWD").unwrap();
let cln = async_run!(cln::Node::with_params(&format!("--developer --plugin={pwd}/target/debug/examples/foo_plugin --plugin={pwd}/target/debug/examples/macros_ex"), "regtest")).unwrap();
cln

async_run!(cln::Node::with_params(&format!("--developer --plugin={pwd}/target/debug/examples/foo_plugin --plugin={pwd}/target/debug/examples/macros_ex"), "regtest")).unwrap()
}

#[fixture]
pub fn lightningd_second() -> cln::Node {
init();
let cln = async_run!(cln::Node::with_params("--developer", "regtest")).unwrap();
cln

async_run!(cln::Node::with_params("--developer", "regtest")).unwrap()
}
}

0 comments on commit 12505dc

Please sign in to comment.