Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new: enforce formatting and clippy lints #36

Merged
merged 8 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
run: cargo test ${{ matrix.cargo_test_opts }}

render_docs:
name: Render docs
name: Code checks
runs-on: ubuntu-latest
env:
RUSTFLAGS: -D warnings
Expand All @@ -42,5 +42,9 @@ jobs:
uses: actions/checkout@v4
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Build docs
- name: Check code formatting
run: cargo fmt --check
- name: Check clippy
run: cargo clippy --all-features
- name: Render docs
run: cargo doc --all-features --no-deps
6 changes: 3 additions & 3 deletions falco_event/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ mod to_bytes;
/// **Footnotes**:
///
/// 1. Loading an owned event from a raw event is technically possible but has no benefits over
/// loading a borrowed event and incurs extra allocations and copies, so to avoid the confusion
/// it's explicitly not supported.
/// loading a borrowed event and incurs extra allocations and copies, so to avoid the confusion
/// it's explicitly not supported.
///
/// 2. Arbitrary serialization and deserialization with [`serde`] is only supported when
/// the `serde` feature of the crate is enabled.
/// the `serde` feature of the crate is enabled.
pub mod types;
2 changes: 1 addition & 1 deletion falco_event/src/events/to_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub trait EventToBytes {
fn write<W: Write>(&self, writer: W) -> std::io::Result<()>;
}

impl<'a> EventToBytes for &'a [u8] {
impl EventToBytes for &[u8] {
fn write<W: Write>(&self, mut writer: W) -> std::io::Result<()> {
writer.write_all(self)
}
Expand Down
3 changes: 2 additions & 1 deletion falco_event/src/types/bytebuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ impl Borrow for Vec<u8> {
}

impl BorrowDeref for Vec<u8> {
type Target<'c> = &'c [u8]
type Target<'c>
= &'c [u8]
where
Self: 'c;

Expand Down
2 changes: 1 addition & 1 deletion falco_event/src/types/net/sockaddr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pub enum OwnedSockAddr {
),
}

impl<'a> Borrowed for SockAddr<'a> {
impl Borrowed for SockAddr<'_> {
type Owned = OwnedSockAddr;
}

Expand Down
2 changes: 1 addition & 1 deletion falco_event/src/types/net/socktuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ pub enum OwnedSockTuple {
),
}

impl<'a> Borrowed for SockTuple<'a> {
impl Borrowed for SockTuple<'_> {
type Owned = OwnedSockTuple;
}

Expand Down
2 changes: 1 addition & 1 deletion falco_event/src/types/path/relative_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ where
#[derive(Debug)]
pub struct OwnedRelativePath(pub PathBuf);

impl<'a> Borrowed for RelativePath<'a> {
impl Borrowed for RelativePath<'_> {
type Owned = OwnedRelativePath;
}

Expand Down
5 changes: 3 additions & 2 deletions falco_event/src/types/string/cstr_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ where
}
}

impl<'a> Borrowed for Vec<&'a CStr> {
impl Borrowed for Vec<&CStr> {
type Owned = Vec<CString>;
}

impl Borrow for Vec<CString> {
type Borrowed<'a> = Vec<&'a CStr>
type Borrowed<'a>
= Vec<&'a CStr>
where
Self: 'a;

Expand Down
3 changes: 2 additions & 1 deletion falco_event/src/types/string/cstr_pair_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ impl<'a> Borrowed for Vec<(&'a CStr, &'a CStr)> {
}

impl Borrow for Vec<(CString, CString)> {
type Borrowed<'a> = Vec<(&'a CStr, &'a CStr)>
type Borrowed<'a>
= Vec<(&'a CStr, &'a CStr)>
where
Self: 'a;

Expand Down
1 change: 0 additions & 1 deletion falco_plugin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ pub mod async_event {
/// The event type that can be emitted from async event plugins
pub use falco_event::events::types::PPME_ASYNCEVENT_E as AsyncEvent;


pub use crate::plugin::async_event::async_handler::AsyncHandler;
pub use crate::plugin::async_event::AsyncEventPlugin;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl<T> StaticFieldGetFallback for T {}
#[allow(missing_debug_implementations)]
pub struct StaticFieldGet<'a, T>(pub &'a T);

impl<'a, T> StaticFieldGet<'a, T>
impl<T> StaticFieldGet<'_, T>
where
T: StaticField + TryFrom<DynamicFieldValue, Error = anyhow::Error>,
{
Expand Down Expand Up @@ -82,7 +82,7 @@ impl<T> StaticFieldSetFallback for T {}
#[allow(missing_debug_implementations)]
pub struct StaticFieldSet<'a, T>(pub &'a mut T);

impl<'a, T> StaticFieldSet<'a, T>
impl<T> StaticFieldSet<'_, T>
where
T: StaticField + TryFrom<DynamicFieldValue, Error = anyhow::Error>,
{
Expand Down
2 changes: 1 addition & 1 deletion falco_plugin/src/plugin/listen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub struct CaptureListenInput<'t> {
pub writer: LazyTableWriter<'t>,
}

impl<'t> CaptureListenInput<'t> {
impl CaptureListenInput<'_> {
pub(in crate::plugin::listen) unsafe fn try_from(
value: *const ss_plugin_capture_listen_input,
last_error: LastError,
Expand Down
2 changes: 1 addition & 1 deletion falco_plugin/src/plugin/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub struct ParseInput<'t> {
pub writer: LazyTableWriter<'t>,
}

impl<'t> ParseInput<'t> {
impl ParseInput<'_> {
pub(in crate::plugin::parse) unsafe fn try_from(
value: *const ss_plugin_event_parse_input,
last_error: LastError,
Expand Down
2 changes: 1 addition & 1 deletion falco_plugin/src/plugin/source/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub trait SourcePlugin: Plugin + SourcePluginExported {
///
/// **Note**: as of API version 3.4.0, this appears unused.
fn list_open_params(&mut self) -> Result<&CStr, anyhow::Error> {
Ok(unsafe { CStr::from_ptr(b"\0".as_ptr().cast()) })
Ok(c"")
}

/// # Open a capture instance
Expand Down
3 changes: 2 additions & 1 deletion falco_plugin/src/plugin/tables/field/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ impl<V: Value + ?Sized, T> Field<V, T> {

impl<V: Value + ?Sized, T> RawFieldValueType for Field<V, T> {
type TableValue = V;
type EntryValue<'a> = <V as Value>::Value<'a>
type EntryValue<'a>
= <V as Value>::Value<'a>
where
Self: 'a;
}
Expand Down
3 changes: 2 additions & 1 deletion falco_plugin/src/plugin/tables/table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ where
M: TableMetadata + Clone + 'static,
{
type AssocData = M;
type Value<'a> = Self
type Value<'a>
= Self
where
Self: 'a;

Expand Down
4 changes: 2 additions & 2 deletions falco_plugin/src/plugin/tables/vtable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub struct TablesInput<'t> {
pub(in crate::plugin::tables) fields_ext: TableFields<'t>,
}

impl<'t> TablesInput<'t> {
impl TablesInput<'_> {
pub(crate) fn try_from(value: &ss_plugin_init_input) -> Result<Option<Self>, TableError> {
if let Some(table_init_input) = unsafe { value.tables.as_ref() } {
let reader_ext = unsafe {
Expand Down Expand Up @@ -113,7 +113,7 @@ impl<'t> TablesInput<'t> {
}
}

impl<'t> TablesInput<'t> {
impl TablesInput<'_> {
/// # List the available tables
///
/// **Note**: this method is of limited utility in actual plugin code (you know the tables you
Expand Down
4 changes: 2 additions & 2 deletions falco_plugin/src/plugin/tables/vtable/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl<'t> LazyTableReader<'t> {
}
}

impl<'t> private::TableReaderImpl for LazyTableReader<'t> {
impl private::TableReaderImpl for LazyTableReader<'_> {
type Error = TableError;

unsafe fn get_table_name(
Expand Down Expand Up @@ -233,7 +233,7 @@ pub struct ValidatedTableReader<'t> {
lifetime: PhantomData<&'t ()>,
}

impl<'t> private::TableReaderImpl for ValidatedTableReader<'t> {
impl private::TableReaderImpl for ValidatedTableReader<'_> {
type Error = std::convert::Infallible;

unsafe fn get_table_name(
Expand Down
4 changes: 2 additions & 2 deletions falco_plugin/src/plugin/tables/vtable/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl<'t> LazyTableWriter<'t> {
}
}

impl<'t> private::TableWriterImpl for LazyTableWriter<'t> {
impl private::TableWriterImpl for LazyTableWriter<'_> {
type Error = TableError;

unsafe fn clear_table(&self, t: *mut ss_plugin_table_t) -> Result<ss_plugin_rc, TableError> {
Expand Down Expand Up @@ -254,7 +254,7 @@ pub struct ValidatedTableWriter<'t> {
lifetime: PhantomData<&'t ()>,
}

impl<'t> private::TableWriterImpl for ValidatedTableWriter<'t> {
impl private::TableWriterImpl for ValidatedTableWriter<'_> {
type Error = std::convert::Infallible;

unsafe fn clear_table(&self, t: *mut ss_plugin_table_t) -> Result<ss_plugin_rc, Self::Error> {
Expand Down
2 changes: 1 addition & 1 deletion falco_plugin_tests/src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl TestDriver for NativeTestDriver {
api: &'static falco_plugin::api::plugin_api,
config: &CStr,
) -> anyhow::Result<Self::Plugin> {
self.0.register_plugin(&api, config)?;
self.0.register_plugin(api, config)?;
Ok(NativePlugin)
}

Expand Down
Loading