Skip to content

Commit

Permalink
Format with group_imports=StdExternalCrate
Browse files Browse the repository at this point in the history
  • Loading branch information
msk committed Nov 14, 2024
1 parent 4da0255 commit 11f9c50
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
rust-version: stable
- uses: actions/checkout@v2
- name: Check formatting
run: cargo fmt -- --check
run: cargo fmt -- --check --config group_imports=StdExternalCrate
- name: Clippy
run: cargo clippy --all-features -- -D warnings -W clippy::pedantic
- name: markdownlint
Expand Down
7 changes: 4 additions & 3 deletions examples/kafka.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use eventio::fluentd::{Entry, ForwardMode};
use eventio::{kafka, Input};
use serde_bytes::ByteBuf;
use std::collections::HashMap;
use std::env;
use std::thread;

use eventio::fluentd::{Entry, ForwardMode};
use eventio::{kafka, Input};
use serde_bytes::ByteBuf;

const TOPIC: &str = "eventio-examples";

fn main() {
Expand Down
3 changes: 2 additions & 1 deletion src/fluentd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
//! [Fluentd Forward Protocol]:
//! https://github.com/fluent/fluentd/wiki/Forward-Protocol-Specification-v1
use std::collections::HashMap;

use serde::{Deserialize, Serialize};
use serde_bytes::ByteBuf;
use std::collections::HashMap;

/// An array representation of pairs of time and record, used in Forward mode.
///
Expand Down
10 changes: 6 additions & 4 deletions src/kafka.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
//! Reading/writing events from/to Apache Kafka servers.
use crate::fluentd::{Entry, ForwardMode};
use crate::Error;
use std::convert::TryInto;
use std::io;

use kafka::consumer::{Consumer, FetchOffset, GroupOffsetStorage};
use kafka::producer::{Producer, Record, RequiredAcks};
use rmp_serde::Serializer;
use serde::Serialize;
use std::convert::TryInto;
use std::io;

use crate::fluentd::{Entry, ForwardMode};
use crate::Error;

/// An event included in a Kafka message at `loc`.
#[derive(Debug)]
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ pub mod pcap;
mod pipeline;
pub mod text;

pub use pipeline::split;
use std::error;
use std::fmt;

pub use self::pipeline::split;

/// A trait for a data source that produces messages of type `Data`.
pub trait Input {
type Data;
Expand Down
9 changes: 6 additions & 3 deletions src/mbox.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//! Reading emails as events from an mbox.
use crate::{BareEvent, Error};
use nom::{bytes::complete::tag, IResult};
use std::io::{self, BufRead, BufReader, Read};

use nom::{bytes::complete::tag, IResult};

use crate::{BareEvent, Error};

/// An email as a byte sequence.
pub type Event = BareEvent;

Expand Down Expand Up @@ -126,10 +128,11 @@ fn mbox_magic(input: &[u8]) -> IResult<&[u8], &[u8]> {

#[cfg(test)]
mod tests {
use crate::Input;
use std::io::Cursor;
use std::thread;

use crate::Input;

fn read_emails(text: &'static [u8]) -> Result<Vec<super::Event>, super::Error> {
let (data_tx, data_rx) = crossbeam_channel::bounded(1);
let (ack_tx, ack_rx) = crossbeam_channel::bounded(1);
Expand Down
9 changes: 6 additions & 3 deletions src/ndarray.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! assembling events from matrix
use crate::{BareEvent, Error};
use ndarray::{Array2, Axis};

use crate::{BareEvent, Error};

/// A single line as a byte sequence.
pub type Event = BareEvent;

Expand Down Expand Up @@ -74,11 +75,13 @@ impl super::Input for Input {

#[cfg(test)]
mod tests {
use crate::{ndarray::Input as ndarray_input, Input};
use ndarray::arr2;
use std::collections::HashMap;
use std::thread;

use ndarray::arr2;

use crate::{ndarray::Input as ndarray_input, Input};

#[test]
fn text_input() {
let data = arr2(&[
Expand Down
9 changes: 6 additions & 3 deletions src/pcap.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
//! Reading packets as events from a pcap input.
use crate::{BareEvent, Error};
use std::io::{self, Read};

use pcap_parser::{
create_reader, data::get_packetdata_ethernet, data::PacketData, traits::PcapReaderIterator,
Block, PcapBlockOwned, PcapError,
};

use crate::{BareEvent, Error};

/// A packet as a byte sequence;
pub type Event = BareEvent;
const PCAP_BUFFER_SIZE: usize = 65536;
Expand Down Expand Up @@ -122,11 +123,13 @@ impl super::Input for Input {

#[cfg(test)]
mod tests {
use crate::{pcap, Input};
use pcap_parser::{LegacyPcapBlock, PcapHeader, ToVec};
use std::io::Cursor;
use std::thread;

use pcap_parser::{LegacyPcapBlock, PcapHeader, ToVec};

use crate::{pcap, Input};

fn create_pcap() -> Cursor<Vec<u8>> {
let fake_content = b"fake packet";
let pkt = LegacyPcapBlock {
Expand Down
6 changes: 4 additions & 2 deletions src/pipeline.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::Event;
use std::thread::{self, JoinHandle};

use crate::Event;

/// Spawns worker threads to process events in parallel.
pub fn split<D, A, I, O, F, S, R>(
data_rx: crossbeam_channel::Receiver<D>,
Expand Down Expand Up @@ -45,9 +46,10 @@ where

#[cfg(test)]
mod tests {
use crate::{text, Input};
use std::thread;

use crate::{text, Input};

#[test]
fn split() {
let text = b"event 1\nevent 2\nevent 3\n";
Expand Down
6 changes: 4 additions & 2 deletions src/text.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! Reading lines as events from a text input.
use crate::{BareEvent, Error};
use std::io::{BufRead, BufReader, Read};

use crate::{BareEvent, Error};

/// A single line as a byte sequence.
pub type Event = BareEvent;

Expand Down Expand Up @@ -93,9 +94,10 @@ impl<T: Read> super::Input for Input<T> {

#[cfg(test)]
mod tests {
use crate::{text, Input};
use std::thread;

use crate::{text, Input};

#[test]
fn text_input() {
let text = b"event 1\nevent 2\r\nevent 3";
Expand Down

0 comments on commit 11f9c50

Please sign in to comment.