Skip to content

Commit

Permalink
Growth ring const function checks (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkuris authored Nov 27, 2023
1 parent b2b4da8 commit 67fc20b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
3 changes: 3 additions & 0 deletions growth-ring/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ tokio = { version = "1.28.1", features = ["tokio-macros", "rt", "macros"] }
name = "growthring"
path = "src/lib.rs"
crate-type = ["dylib", "rlib", "staticlib"]

[lints.clippy]
missing_const_for_fn = "warn"
6 changes: 3 additions & 3 deletions growth-ring/src/wal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn sort_fids(file_nbit: u64, mut fids: Vec<u64>) -> Vec<(u8, u64)> {
}
}

fn counter_lt(a: u32, b: u32) -> bool {
const fn counter_lt(a: u32, b: u32) -> bool {
if u32::abs_diff(a, b) > u32::MAX / 2 {
b < a
} else {
Expand Down Expand Up @@ -125,10 +125,10 @@ impl WalRingId {
counter: 0,
}
}
pub fn get_start(&self) -> WalPos {
pub const fn get_start(&self) -> WalPos {
self.start
}
pub fn get_end(&self) -> WalPos {
pub const fn get_end(&self) -> WalPos {
self.end
}
}
Expand Down
8 changes: 4 additions & 4 deletions growth-ring/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub trait FailGen {
struct FileContentEmul(RefCell<Vec<u8>>);

impl FileContentEmul {
pub fn new() -> Self {
pub const fn new() -> Self {
FileContentEmul(RefCell::new(Vec::new()))
}
}
Expand Down Expand Up @@ -187,7 +187,7 @@ pub struct SingleFailGen {
}

impl SingleFailGen {
pub fn new(fail_point: usize) -> Self {
pub const fn new(fail_point: usize) -> Self {
SingleFailGen {
cnt: std::cell::Cell::new(0),
fail_point,
Expand All @@ -214,7 +214,7 @@ impl FailGen for ZeroFailGen {
pub struct CountFailGen(std::cell::Cell<usize>);

impl CountFailGen {
pub fn new() -> Self {
pub const fn new() -> Self {
CountFailGen(std::cell::Cell::new(0))
}
pub fn get_count(&self) -> usize {
Expand All @@ -234,7 +234,7 @@ impl FailGen for CountFailGen {
pub struct PaintStrokes(Vec<(u32, u32, u32)>);

impl PaintStrokes {
pub fn new() -> Self {
pub const fn new() -> Self {
PaintStrokes(Vec::new())
}

Expand Down

0 comments on commit 67fc20b

Please sign in to comment.