Skip to content

Commit

Permalink
🎨 fix rust formatter
Browse files Browse the repository at this point in the history
We're in a situation where my Rust installation is older than the
tools available on GitHub. A parameter for the Rust formatter has
changed and I don't know how to make it work for both versions.
However, I like the way it formats function parameters when I
comment-out the config, so I'll commit this rather large change.
  • Loading branch information
rneswold committed Jun 3, 2023
1 parent 1791b15 commit cc75f0c
Show file tree
Hide file tree
Showing 18 changed files with 280 additions and 109 deletions.
2 changes: 1 addition & 1 deletion .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#combine_control_expr = false
#condense_wildcard_suffixes = true
edition = "2018"
fn_args_layout = "Compressed"
#fn_params_layout = "Compressed"
#format_strings = true
#indent_style = "Visual"
newline_style = "Unix"
Expand Down
79 changes: 58 additions & 21 deletions backends/drmem-db-redis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,9 @@ impl ReadingStream {
}

pub fn new(
con: AioConnection, key: &str, id: Option<time::SystemTime>,
con: AioConnection,
key: &str,
id: Option<time::SystemTime>,
) -> Self {
let key = key.to_string();
let id = id.map(Self::ts_to_id).unwrap_or_else(|| String::from("$"));
Expand Down Expand Up @@ -344,7 +346,8 @@ impl Stream for ReadingStream {
// timeout parameter to periodically wake up and retry the read.

fn poll_next(
mut self: Pin<&mut Self>, cx: &mut Context<'_>,
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<Self::Item>> {
loop {
// If there is a `Poll::Ready` return value, then redis
Expand Down Expand Up @@ -409,7 +412,9 @@ pub struct RedisStore {

impl RedisStore {
fn make_client(
cfg: &config::Config, name: &Option<String>, pword: &Option<String>,
cfg: &config::Config,
name: &Option<String>,
pword: &Option<String>,
) -> Result<redis::Client> {
use redis::{ConnectionAddr, ConnectionInfo, RedisConnectionInfo};

Expand All @@ -430,7 +435,9 @@ impl RedisStore {
// Creates a single-user connection to redis.

async fn make_connection(
cfg: &config::Config, name: Option<String>, pword: Option<String>,
cfg: &config::Config,
name: Option<String>,
pword: Option<String>,
) -> Result<AioConnection> {
let client = Self::make_client(cfg, &name, &pword)?;

Expand All @@ -445,7 +452,9 @@ impl RedisStore {
// Creates a mulitplexed connection to redis.

async fn make_mplex_connection(
cfg: &config::Config, name: Option<String>, pword: Option<String>,
cfg: &config::Config,
name: Option<String>,
pword: Option<String>,
) -> Result<AioMplexConnection> {
let client = Self::make_client(cfg, &name, &pword)?;

Expand All @@ -466,7 +475,9 @@ impl RedisStore {
/// used for credentials when connecting to `redis`.
pub async fn new(
cfg: &config::Config, name: Option<String>, pword: Option<String>,
cfg: &config::Config,
name: Option<String>,
pword: Option<String>,
) -> Result<Self> {
let db_con = Self::make_mplex_connection(cfg, name, pword).await?;

Expand All @@ -491,7 +502,9 @@ impl RedisStore {
}

fn init_device_cmd(
name: &str, driver: &str, units: &Option<String>,
name: &str,
driver: &str,
units: &Option<String>,
) -> redis::Pipeline {
let hist_key = Self::hist_key(name);
let info_key = Self::info_key(name);
Expand Down Expand Up @@ -594,7 +607,9 @@ impl RedisStore {
}

fn report_bounded_new_value_cmd(
key: &str, val: &device::Value, mh: usize,
key: &str,
val: &device::Value,
mh: usize,
) -> redis::Cmd {
let opts = redis::streams::StreamMaxlen::Approx(mh);
let data = [("value", to_redis(val))];
Expand All @@ -603,7 +618,9 @@ impl RedisStore {
}

fn hash_to_info(
st: &SettingTable, name: &device::Name, hmap: &HashMap<String, String>,
st: &SettingTable,
name: &device::Name,
hmap: &HashMap<String, String>,
) -> Result<client::DevInfoReply> {
// Redis doesn't return an error if the key doesn't exist; it
// returns an empty array. So if our HashMap is empty, the key
Expand Down Expand Up @@ -655,7 +672,8 @@ impl RedisStore {
// `client::DevInfoReply` containing the information.

async fn lookup_device(
&mut self, name: device::Name,
&mut self,
name: device::Name,
) -> Result<client::DevInfoReply> {
let info = Self::device_info_cmd(name.to_string().as_str())
.query_async::<AioMplexConnection, HashMap<String, String>>(
Expand Down Expand Up @@ -688,7 +706,8 @@ impl RedisStore {
}

fn parse_last_value(
name: &str, reply: &redis::Value,
name: &str,
reply: &redis::Value,
) -> Option<device::Reading> {
if redis::Value::Bulk(vec![]) == *reply {
warn!("no previous value for {}", name);
Expand Down Expand Up @@ -808,7 +827,10 @@ impl RedisStore {
// values.

async fn init_device(
&mut self, name: &str, driver: &str, units: &Option<String>,
&mut self,
name: &str,
driver: &str,
units: &Option<String>,
) -> Result<()> {
debug!("initializing {}", name);
Self::init_device_cmd(name, driver, units)
Expand All @@ -821,7 +843,9 @@ impl RedisStore {
// values.

fn mk_report_func(
&self, name: &str, max_history: &Option<usize>,
&self,
name: &str,
max_history: &Option<usize>,
) -> ReportReading<device::Value> {
let db_con = self.db_con.clone();
let name = String::from(name);
Expand Down Expand Up @@ -866,8 +890,11 @@ impl Store for RedisStore {
/// Registers a device in the redis backend.
async fn register_read_only_device(
&mut self, driver_name: &str, name: &device::Name,
units: &Option<String>, max_history: &Option<usize>,
&mut self,
driver_name: &str,
name: &device::Name,
units: &Option<String>,
max_history: &Option<usize>,
) -> Result<(ReportReading<device::Value>, Option<device::Value>)> {
let name = name.to_string();

Expand All @@ -885,8 +912,11 @@ impl Store for RedisStore {
}

async fn register_read_write_device(
&mut self, driver_name: &str, name: &device::Name,
units: &Option<String>, max_history: &Option<usize>,
&mut self,
driver_name: &str,
name: &device::Name,
units: &Option<String>,
max_history: &Option<usize>,
) -> Result<(
ReportReading<device::Value>,
RxDeviceSetting,
Expand Down Expand Up @@ -920,7 +950,8 @@ impl Store for RedisStore {
// client will be from GraphQL requests.

async fn get_device_info(
&mut self, pattern: &Option<String>,
&mut self,
pattern: &Option<String>,
) -> Result<Vec<client::DevInfoReply>> {
// Get a list of all the keys that match the pattern. For
// Redis, these keys will have "#info" appended at the end.
Expand Down Expand Up @@ -956,7 +987,9 @@ impl Store for RedisStore {
// API.

async fn set_device(
&self, name: device::Name, value: device::Value,
&self,
name: device::Name,
value: device::Value,
) -> Result<device::Value> {
if let Some(tx) = self.table.get(&name) {
let (tx_rpy, rx_rpy) = oneshot::channel();
Expand All @@ -982,7 +1015,9 @@ impl Store for RedisStore {
}

async fn get_setting_chan(
&self, name: device::Name, _own: bool,
&self,
name: device::Name,
_own: bool,
) -> Result<TxDeviceSetting> {
if let Some(tx) = self.table.get(&name) {
Ok(tx.clone())
Expand All @@ -992,7 +1027,9 @@ impl Store for RedisStore {
}

async fn monitor_device(
&mut self, name: device::Name, start: Option<DateTime<Utc>>,
&mut self,
name: device::Name,
start: Option<DateTime<Utc>>,
end: Option<DateTime<Utc>>,
) -> Result<device::DataStream<device::Reading>> {
match Self::make_connection(&self.cfg, None, None).await {
Expand Down
31 changes: 23 additions & 8 deletions backends/drmem-db-simple/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ struct DeviceInfo {

impl DeviceInfo {
pub fn create(
owner: String, units: Option<String>,
owner: String,
units: Option<String>,
tx_setting: Option<TxDeviceSetting>,
) -> DeviceInfo {
let (tx, _) = broadcast::channel(CHAN_SIZE);
Expand All @@ -74,7 +75,8 @@ pub async fn open(_cfg: &config::Config) -> Result<impl Store> {
// instances of this function to record the latest value of a device.

fn mk_report_func(
di: &DeviceInfo, name: &device::Name,
di: &DeviceInfo,
name: &device::Name,
) -> ReportReading<device::Value> {
let reading = di.reading.clone();
let name = name.to_string();
Expand Down Expand Up @@ -140,7 +142,10 @@ impl Store for SimpleStore {
/// this function doesn't allocate a channel to provide settings.
async fn register_read_only_device(
&mut self, driver: &str, name: &device::Name, units: &Option<String>,
&mut self,
driver: &str,
name: &device::Name,
units: &Option<String>,
_max_history: &Option<usize>,
) -> Result<(ReportReading<device::Value>, Option<device::Value>)> {
// Check to see if the device name already exists.
Expand Down Expand Up @@ -195,7 +200,10 @@ impl Store for SimpleStore {
/// resources.
async fn register_read_write_device(
&mut self, driver: &str, name: &device::Name, units: &Option<String>,
&mut self,
driver: &str,
name: &device::Name,
units: &Option<String>,
_max_history: &Option<usize>,
) -> Result<(
ReportReading<device::Value>,
Expand Down Expand Up @@ -261,7 +269,8 @@ impl Store for SimpleStore {
}

async fn get_device_info(
&mut self, pattern: &Option<String>,
&mut self,
pattern: &Option<String>,
) -> Result<Vec<client::DevInfoReply>> {
let pred: Box<dyn FnMut(&(&device::Name, &DeviceInfo)) -> bool> =
if let Some(pattern) = pattern {
Expand Down Expand Up @@ -306,7 +315,9 @@ impl Store for SimpleStore {
}

async fn set_device(
&self, name: device::Name, value: device::Value,
&self,
name: device::Name,
value: device::Value,
) -> Result<device::Value> {
if let Some(di) = self.0.get(&name) {
if let Some(tx) = &di.tx_setting {
Expand All @@ -332,7 +343,9 @@ impl Store for SimpleStore {
}

async fn get_setting_chan(
&self, name: device::Name, _own: bool,
&self,
name: device::Name,
_own: bool,
) -> Result<TxDeviceSetting> {
if let Some(di) = self.0.get(&name) {
if let Some(tx) = &di.tx_setting {
Expand All @@ -348,7 +361,9 @@ impl Store for SimpleStore {
// by all new updates.

async fn monitor_device(
&mut self, name: device::Name, start: Option<DateTime<Utc>>,
&mut self,
name: device::Name,
start: Option<DateTime<Utc>>,
end: Option<DateTime<Utc>>,
) -> Result<device::DataStream<device::Reading>> {
// Look-up the name of the device. If it doesn't exist, return
Expand Down
10 changes: 7 additions & 3 deletions drivers/drmem-drv-ntp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ mod server {
// method.

fn update_host_info(
mut state: (Option<String>, Option<f64>, Option<f64>), item: &str,
mut state: (Option<String>, Option<f64>, Option<f64>),
item: &str,
) -> (Option<String>, Option<f64>, Option<f64>) {
match item.split('=').collect::<Vec<&str>>()[..] {
["srcadr", adr] => state.0 = Some(String::from(adr)),
Expand Down Expand Up @@ -367,7 +368,9 @@ impl driver::API for Instance {
type DeviceSet = Devices;

fn register_devices(
core: driver::RequestChan, _: &DriverConfig, max_history: Option<usize>,
core: driver::RequestChan,
_: &DriverConfig,
max_history: Option<usize>,
) -> Pin<Box<dyn Future<Output = Result<Self::DeviceSet>> + Send>> {
// It's safe to use `.unwrap()` for these names because, in a
// fully-tested, released version of this driver, we would
Expand Down Expand Up @@ -426,7 +429,8 @@ impl driver::API for Instance {
}

fn run<'a>(
&'a mut self, devices: Arc<Mutex<Devices>>,
&'a mut self,
devices: Arc<Mutex<Devices>>,
) -> Pin<Box<dyn Future<Output = Infallible> + Send + 'a>> {
let fut = async move {
// Record the peer's address in the "cfg" field of the
Expand Down
11 changes: 8 additions & 3 deletions drivers/drmem-drv-sump/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ impl State {
// will be returned.

pub fn off_event(
&mut self, stamp: u64, gpm: f64,
&mut self,
stamp: u64,
gpm: f64,
) -> Option<(u64, f64, f64)> {
match *self {
State::Unknown => {
Expand Down Expand Up @@ -281,7 +283,9 @@ impl driver::API for Instance {
type DeviceSet = Devices;

fn register_devices(
core: driver::RequestChan, _: &DriverConfig, max_history: Option<usize>,
core: driver::RequestChan,
_: &DriverConfig,
max_history: Option<usize>,
) -> Pin<Box<dyn Future<Output = Result<Self::DeviceSet>> + Send>> {
let service_name = "service".parse::<device::Base>().unwrap();
let state_name = "state".parse::<device::Base>().unwrap();
Expand Down Expand Up @@ -347,7 +351,8 @@ impl driver::API for Instance {
}

fn run<'a>(
&'a mut self, devices: Arc<Mutex<Devices>>,
&'a mut self,
devices: Arc<Mutex<Devices>>,
) -> Pin<Box<dyn Future<Output = Infallible> + Send + 'a>> {
let fut = async move {
// Record the peer's address in the "cfg" field of the
Expand Down
Loading

0 comments on commit cc75f0c

Please sign in to comment.