Skip to content

Commit

Permalink
Merge pull request #60 from scott-ainsworth/maint/59-cleanup-lints
Browse files Browse the repository at this point in the history
Maint/59 cleanup lints
  • Loading branch information
scott-ainsworth authored Dec 21, 2021
2 parents d8f5e70 + 4829fde commit be038df
Show file tree
Hide file tree
Showing 21 changed files with 278 additions and 163 deletions.
37 changes: 36 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,44 @@
[build]
incremental = false
rustflags = [
"-W", "clippy::all",
# "-W", "clippy::pedantic",
"-W", "absolute_paths_not_starting_with_crate",
"-W", "box_pointers",
"-W", "deprecated_in_future",
"-W", "elided_lifetimes_in_paths",
"-W", "explicit_outlives_requirements",
"-W", "keyword_idents",
"-W", "macro_use_extern_crate",
"-W", "meta_variable_misuse",
"-W", "missing_abi",
"-W", "missing_copy_implementations",
"-W", "missing_debug_implementations",
# "-W", "missing_docs",
"-W", "non_ascii_idents",
"-W", "noop_method_call",
"-W", "pointer_structural_match",
"-W", "rust_2018_idioms",
"-W", "rust_2021_incompatible_closure_captures",
"-W", "rust_2021_incompatible_or_patterns",
"-W", "rust_2021_prefixes_incompatible_syntax",
"-W", "rust_2021_prelude_collisions",
"-W", "single_use_lifetimes",
"-W", "trivial_numeric_casts",
"-W", "unreachable_pub",
"-W", "unsafe_code",
"-W", "unsafe_op_in_unsafe_fn",
"-W", "unstable_features",
"-W", "unused_crate_dependencies",
"-W", "unused_extern_crates",
"-W", "unused_import_braces",
"-W", "unused_lifetimes",
"-W", "unused_qualifications",
"-W", "unused_results",
"-W", "variant_size_differences",
"-C", "link-dead-code",
# "-C", "overflow-checks=off",
"-C", "panic=abort",
# "-C", "panic=abort",
# "-Z", "profile",
# "-Z", "panic_abort_tests"
]
Expand Down
7 changes: 7 additions & 0 deletions .cspell/custom-dictionary-folder-avahi-aliases-rs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@
Ainsworth
Airtonix
avahi
clippy
cname
codegen
dbus
dups
Freedesktop
HINFO
idents
IDNA
INET
locl
luarntlemercier
rdata
repr
RUSTDOCFLAGS
RUSTFLAGS
signon
structopt
sysinfo
Expand Down
116 changes: 65 additions & 51 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,64 +1,78 @@
# https://github.com/rust-lang/rustfmt/blob/master/Configurations.md

version = "Two"
tab_spaces = 4
hard_tabs = false
# Maximum width of each line (Default: 100)
max_width = 96
newline_style = "Unix"

format_generated_files = false
struct_variant_width = 96
comment_width = 96
# Use tab characters for indentation, spaces for alignment (Default: false)
hard_tabs = false

# Number of spaces per tab (Default: 4)
tab_spaces = 4

# Unix or Windows line endings [Auto|Windows|Unix|Native] (Default: Auto)
newline_style = "Auto"

# Whether to use different formatting for items and expressions if they satisfy a heuristic
# notion of 'small' [Off|Max|Default] (Default: Default)
use_small_heuristics = "Max"
unstable_features = true

binop_separator = "Front"
blank_lines_lower_bound = 0
blank_lines_upper_bound = 2
#brace_style = "SameLineWhere"
brace_style = "PreferSameLine"
condense_wildcard_suffixes = true
#control_brace_style = "ClosingNextLine"
control_brace_style = "AlwaysSameLine"
# Maximum width of the args of a function call before falling back to vertical formatting.
# (Default: 60)
# fn_call_width = 60 # overridden by use_small_heuristics = "Max"

edition = "2021"
# Maximum width of the args of a function-like attributes before falling back to vertical
# formatting. (Default: 70)
# attr_fn_like_width = 70 # overridden by use_small_heuristics = "Max"

empty_item_single_line = true
enum_discrim_align_threshold = 20
# Maximum width in the body of a struct lit before falling back to vertical formatting.
# (Default: 18)
# struct_lit_width = 18 # overridden by use_small_heuristics = "Max"

error_on_line_overflow = true
error_on_unformatted = true
# Maximum width in the body of a struct variant before falling back to vertical formatting.
# (Default: 35)
# struct_variant_width = 35 # overridden by use_small_heuristics = "Max"

# Maximum width of an array literal before falling back to vertical formatting. (Default: 60)
# array_width = 60 # overridden by use_small_heuristics = "Max"

# Maximum length of a chain to fit on a single line. (Default: 60)
# chain_width = 60 # overridden by use_small_heuristics = "Max"

# Maximum line length for single line if-else expressions. A value of zero means always break
# if-else expressions. (Default: 50)
# single_line_if_else_max_width = 50 # overridden by use_small_heuristics = "Max"

# Reorder import and extern crate statements alphabetically (Default: true)
reorder_imports = true

# Reorder module statements alphabetically in group (Default: true)
reorder_modules = true

# Remove nested parens (Default: true)
remove_nested_parens = true

# Determines whether leading pipes are emitted on match arms [Always|Never|Preserve]
# (Default: Never)
match_arm_leading_pipes = "Never"

# Control the layout of arguments in a function [Compressed|Tall|Vertical] (Default: Tall)
fn_args_layout = "Compressed"
fn_single_line = true
force_explicit_abi = true
force_multiline_blocks = false
format_code_in_doc_comments = true
format_macro_matchers = false
format_macro_bodies = false
format_strings = false
hex_literal_case = "lower"
imports_granularity = "Module"
match_block_trailing_comma = true

# The edition of the parser (RFC 2052) [2015|2018|2021] (Default: 2015)
edition = "2021"

# Merge multiple `#[derive(...)]` into a single one (Default: true)
merge_derives = true
normalize_comments = true
normalize_doc_attributes = true
overflow_delimited_expr = true
remove_nested_parens = true
#reorder_impl_items = true
reorder_imports = false
group_imports = "StdExternalCrate"
reorder_modules = true
report_fixme = "Unnumbered"
report_todo = "Unnumbered"
space_after_colon = true
space_before_colon = false
spaces_around_ranges = false
struct_lit_single_line = true
trailing_comma = "Vertical"
trailing_semicolon = true
type_punctuation_density = "Wide"
use_try_shorthand = true
where_single_line = false
wrap_comments = true

# Replace uses of the try! macro by the ? shorthand (Default: false)
use_try_shorthand = false

# Use field initialization shorthand if possible (Default: false)
use_field_init_shorthand = false

# Always print the abi for extern items (Default: true)
force_explicit_abi = true

# Prints the names of mismatched files that were formatted. Prints the names of files that
# would be formated when used with `--check` mode (Default: false)
print_misformatted_file_names = true
30 changes: 2 additions & 28 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
[package]
name = "avahi-aliases"
version = "1.1.0-alpha"
authors = [ "Scott G. Ainsworth" ]
edition = "2021"
description = "Avahi aliases manager"
readme = "README.md"
license = "MIT OR Apache-2.0"
keywords = ["avahi", "zeroconf", "bonjour"]
categories = ["command-line-utilities", "os::linux-apis"]
publish = false
default-run = "avahi-alias"

[badges]
maintenance = { status = "experimental" }
[workspace]
members = [ "avahi-alias", "avahi-alias-daemon", "avahi-aliases-lib" ]

[profile.release]
debug = false
Expand All @@ -21,17 +8,4 @@ panic = "abort"
codegen-units = 1
opt-level = "z"

[dependencies]
anyhow = "1.0.45"
clap = "2.33.3"
dbus = "0.9.5"
env_logger = "0.9.0"
log = "0.4.14"
paw = "1.0.0"
regex = "1.5.4"
time = { version = "0.3.5", features = [ "formatting" ] }
structopt = { version = "0.3.25", default-features = false, features = [ "paw" ] }
sysinfo = "0.21.1"
syslog = "5.0.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
25 changes: 25 additions & 0 deletions avahi-alias-daemon/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "avahi-alias-daemon"
authors = [ "Scott G. Ainsworth" ]
version = "1.1.0-alpha"
edition = "2021"
description = "Avahi aliases manager"
license = "MIT OR Apache-2.0"
keywords = ["avahi", "zeroconf", "bonjour"]
categories = ["command-line-utilities", "os::linux-apis"]
publish = false

[badges]
maintenance = { status = "experimental" }

[dependencies]
avahi-aliases = { path = "../avahi-aliases-lib" }
anyhow = "1.0.45"
clap = "2.33.3"
dbus = "0.9.5"
log = "0.4.14"
paw = "1.0.0"
time = { version = "0.3.5", features = [ "formatting" ] }
structopt = { version = "0.3.25", default-features = false, features = [ "paw" ] }

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
25 changes: 13 additions & 12 deletions src/bin/avahi-alias-daemon.rs → avahi-alias-daemon/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#![warn(clippy::all)]

use std::{fs, thread, time};

use ::time::format_description::well_known::Rfc3339;
use ::time::OffsetDateTime;
use structopt::StructOpt;
use anyhow::{Context, Result};
use avahi_aliases::{
avahi_dbus, encoding, init_console_logging, init_syslog_logging, AliasesFile, DaemonOpts,
};
use avahi_dbus::{avahi, OrgFreedesktopAvahiEntryGroup, OrgFreedesktopAvahiServer};
use avahi_dbus::avahi;
use avahi_dbus::entry_group::OrgFreedesktopAvahiEntryGroup;
use avahi_dbus::server::OrgFreedesktopAvahiServer;
use structopt::StructOpt;

#[derive(PartialEq)]
struct ModifiedSize {
Expand All @@ -32,7 +32,7 @@ fn main(opts: DaemonOpts) {
Err(error) => {
log::error!("Error: {}", error);
std::process::exit(1)
},
}
}
}

Expand Down Expand Up @@ -60,7 +60,7 @@ fn init_logging(verbose: bool, debug: bool, syslog: bool) -> Result<()> {
false => {
init_console_logging(verbose, debug)?;
Ok(())
},
}
}
}

Expand All @@ -84,7 +84,7 @@ fn load_aliases(file_name: &str, modified_size: &ModifiedSize) -> Result<Aliases
}

fn load_publish_loop(
avahi_server_proxy: &avahi_dbus::DBusProxy, file_name: &str,
avahi_server_proxy: &avahi_dbus::DBusProxy<'_, '_>, file_name: &str,
polling_interval: time::Duration, timeout: time::Duration, ttl: time::Duration,
) -> Result<()> {
let mut modified_size = ModifiedSize { last_modified: time::UNIX_EPOCH, len: 0 };
Expand All @@ -111,9 +111,10 @@ fn load_publish_loop(
}
}

fn publish_aliases<'a>(
avahi_server_proxy: &avahi_dbus::DBusProxy, aliases_file: &AliasesFile, file_name: &'a str,
modified_size: &ModifiedSize, ttl: time::Duration, timeout: time::Duration,
fn publish_aliases(
avahi_server_proxy: &avahi_dbus::DBusProxy<'_, '_>, aliases_file: &AliasesFile,
file_name: &str, modified_size: &ModifiedSize, ttl: time::Duration,
timeout: time::Duration,
) -> Result<()> {
let last_modified: OffsetDateTime = modified_size.last_modified.into();
if aliases_file.alias_count() == 0 {
Expand Down Expand Up @@ -149,7 +150,7 @@ fn publish_aliases<'a>(
ttl.as_secs() as u32,
rdata.clone(),
)?;
},
}
Err(a) => log::info!(r#"WARNING: invalid alias "{}" ignored"#, a),
}
}
Expand All @@ -168,7 +169,7 @@ fn signon_app() {
log::info!("{} {} {}", app.get_name(), clap::crate_version!(), clap::crate_authors!());
}

fn signon_avahi(avahi_server_proxy: &avahi_dbus::DBusProxy) -> Result<()> {
fn signon_avahi(avahi_server_proxy: &avahi_dbus::DBusProxy<'_, '_>) -> Result<()> {
let version = avahi_server_proxy.get_version_string()?;
let host_fqdn = avahi_server_proxy.get_host_name_fqdn()?;
log::info!("{}, host fqdn: {}", version, host_fqdn);
Expand Down
22 changes: 22 additions & 0 deletions avahi-alias/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "avahi-alias"
authors = [ "Scott G. Ainsworth" ]
version = "1.1.0-alpha"
edition = "2021"
description = "Avahi aliases manager"
license = "MIT OR Apache-2.0"
keywords = ["avahi", "zeroconf", "bonjour"]
categories = ["command-line-utilities", "os::linux-apis"]
publish = false

[badges]
maintenance = { status = "experimental" }

[dependencies]
avahi-aliases = { path = "../avahi-aliases-lib" }
anyhow = "1.0.45"
log = "0.4.14"
paw = "1.0.0"
#structopt = { version = "0.3.25", default-features = false, features = [ "paw" ] }

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
4 changes: 1 addition & 3 deletions src/bin/avahi-alias.rs → avahi-alias/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![warn(clippy::all)]

use std::collections::HashSet;

use anyhow::Result;
Expand Down Expand Up @@ -50,7 +48,7 @@ fn list(filename: &str) -> Result<()> {
Ok(alias) => println!("{}", alias),
Err(invalid_alias) => {
println!(r#"ERROR: invalid alias "{}""#, invalid_alias)
},
}
}
}
Ok(())
Expand Down
Loading

0 comments on commit be038df

Please sign in to comment.