Skip to content

Commit

Permalink
Move the 'id', 'rcu' and 'vec_map' modules under 'util'.
Browse files Browse the repository at this point in the history
  • Loading branch information
martinling authored and miek committed Oct 31, 2024
1 parent 0e0d0af commit b5322cc
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 22 deletions.
12 changes: 8 additions & 4 deletions src/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::sync::atomic::Ordering::{Acquire, Release};
use std::sync::Arc;
use std::mem::size_of;

use crate::id::{Id, HasLength};
use crate::database::{
CompactReader,
CompactWriter,
Expand All @@ -19,10 +18,15 @@ use crate::database::{
data_stream,
data_stream_with_block_size,
};
use crate::rcu::SingleWriterRcu;
use crate::vec_map::{Key, VecMap};
use crate::usb::{self, prelude::*};
use crate::util::{Bytes, fmt_count, fmt_size};
use crate::util::{
id::{Id, HasLength},
rcu::SingleWriterRcu,
vec_map::{Key, VecMap},
Bytes,
fmt_count,
fmt_size,
};

use anyhow::{Context, Error, bail};
use arc_swap::{ArcSwap, ArcSwapOption};
Expand Down
3 changes: 1 addition & 2 deletions src/database/compact_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ use crate::database::{
data_stream::{data_stream, DataReader, DataWriter, DataIterator},
index_stream::{index_stream, IndexReader, IndexWriter, IndexIterator},
};
use crate::id::Id;
use crate::util::{fmt_count, fmt_size};
use crate::util::{id::Id, fmt_count, fmt_size};

type Offset = Id<u8>;
type SegmentId = Id<u8>;
Expand Down
2 changes: 1 addition & 1 deletion src/database/data_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::ops::{Deref, Range};
use anyhow::Error;
use bytemuck::{bytes_of, cast_slice, from_bytes, Pod};

use crate::id::Id;
use crate::util::id::Id;
use crate::database::stream::{
stream,
StreamReader,
Expand Down
3 changes: 1 addition & 2 deletions src/database/index_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ use crate::database::{
DataIterator
},
};
use crate::id::Id;
use crate::util::{fmt_count, fmt_size};
use crate::util::{id::Id, fmt_count, fmt_size};

/// Unique handle for append-only write access to an index.
pub struct IndexWriter<Position, Value, const S: usize = MIN_BLOCK> {
Expand Down
6 changes: 4 additions & 2 deletions src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ use std::sync::Arc;
use anyhow::{Context, Error, bail};

use crate::capture::prelude::*;
use crate::rcu::SingleWriterRcu;
use crate::usb::{self, prelude::*, validate_packet};
use crate::vec_map::VecMap;
use crate::util::{
rcu::SingleWriterRcu,
vec_map::VecMap,
};

struct EndpointData {
device_id: DeviceId,
Expand Down
3 changes: 0 additions & 3 deletions src/fuzzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ use libfuzzer_sys::{arbitrary::{Arbitrary, Unstructured}, fuzz_target};
mod capture;
mod database;
mod decoder;
mod id;
mod pcap;
mod rcu;
mod usb;
mod util;
mod vec_map;

use capture::create_capture;
use decoder::Decoder;
Expand Down
6 changes: 4 additions & 2 deletions src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ use crate::capture::{
PacketId,
INVALID_EP_ID,
};
use crate::id::HasLength;
use crate::usb::{self, prelude::*, validate_packet};
use crate::util::{Bytes, fmt_count, fmt_size, titlecase};
use crate::util::{
id::HasLength,
Bytes, fmt_count, fmt_size, titlecase
};

pub trait ItemSource<Item, ViewMode> {
/// Fetch an item from the source by index, relative to either the root
Expand Down
3 changes: 0 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,12 @@ mod backend;
mod capture;
mod database;
mod decoder;
mod id;
mod item;
mod pcap;
mod rcu;
mod test_cynthion;
mod ui;
mod usb;
mod util;
mod vec_map;
mod version;

use gtk::prelude::*;
Expand Down
6 changes: 4 additions & 2 deletions src/usb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ use num_enum::{IntoPrimitive, FromPrimitive};
use derive_more::{From, Into, Display};
use usb_ids::FromId;

use crate::util::titlecase;
use crate::vec_map::VecMap;
use crate::util::{
vec_map::VecMap,
titlecase
};

fn crc16(bytes: &[u8]) -> u16 {
const CRC16: Crc<u16> = Crc::<u16>::new(&CRC_16_USB);
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions src/util.rs → src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ use num_format::{Locale, ToFormattedString};
use humansize::{SizeFormatter, BINARY};
use itertools::Itertools;

pub mod id;
pub mod vec_map;
pub mod rcu;

pub fn fmt_count(count: u64) -> String {
count.to_formatted_string(&Locale::en)
}
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/vec_map.rs → src/util/vec_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::ops::{Index, IndexMut};
use std::marker::PhantomData;
use std::slice::Iter;

use crate::id::Id;
use crate::util::id::Id;

pub trait Key {
fn id(self) -> usize;
Expand Down

0 comments on commit b5322cc

Please sign in to comment.