Skip to content

Commit

Permalink
fix suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
0xLucqs committed Jan 25, 2024
1 parent 3700ed9 commit 73a3a80
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 30 deletions.
16 changes: 4 additions & 12 deletions .github/workflows/check_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@ on:
name: Check and Lint and wasm

jobs:
check:
name: Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install rust
run: rustup show
- name: Check
run: cargo check
build-wasm:
name: Build wasm
runs-on: ubuntu-latest
Expand Down Expand Up @@ -47,14 +38,15 @@ jobs:
run: rustup show
- name: Clippy all features
run: cargo clippy --all-features

clippy-default-features:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install rust
run: rustup show
- name: Clippy all features
- name: Clippy default features
run: cargo clippy

clippy-wasm:
Expand All @@ -64,5 +56,5 @@ jobs:
- uses: actions/checkout@v3
- name: Install rust
run: rustup show
- name: Clippy all features
run: cargo clippy
- name: Clippy wasm
run: cargo clippy --no-default-features
1 change: 1 addition & 0 deletions src/bonsai_database.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{changes::ChangeKeyType, error::BonsaiStorageError, id::Id};
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

#[derive(Debug, Hash, PartialEq, Eq)]
Expand Down
3 changes: 1 addition & 2 deletions src/changes.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use crate::id::Id;
use alloc::vec::Vec;
use serde::{Deserialize, Serialize};
#[cfg(feature = "std")]
use std::collections::{hash_map::Entry, HashMap, VecDeque};
#[cfg(not(feature = "std"))]
use {
alloc::collections::VecDeque,
alloc::{collections::VecDeque, vec::Vec},
hashbrown::{hash_map::Entry, HashMap},
};

Expand Down
18 changes: 13 additions & 5 deletions src/databases/hashmap_db.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
use alloc::fmt::Display;
use alloc::vec::Vec;
use alloc::{collections::BTreeMap, string::ToString};
#[cfg(not(feature = "std"))]
use alloc::{
fmt,
fmt::Display,
vec::Vec,
{collections::BTreeMap, string::ToString},
};
#[cfg(not(feature = "std"))]
use hashbrown::HashMap;
#[cfg(feature = "std")]
use std::collections::HashMap;
use std::{
collections::{BTreeMap, HashMap},
fmt,
fmt::Display,
};

use crate::{
bonsai_database::BonsaiPersistentDatabase, error::BonsaiStorageError, id::Id, BonsaiDatabase,
Expand All @@ -14,7 +22,7 @@ use crate::{
pub struct HashMapDbError {}

impl Display for HashMapDbError {
fn fmt(&self, f: &mut alloc::fmt::Formatter<'_>) -> alloc::fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "")
}
}
Expand Down
1 change: 1 addition & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(not(feature = "std"))]
use alloc::string::String;
/// All errors that can be returned by BonsaiStorage.
#[derive(Debug)]
Expand Down
1 change: 1 addition & 0 deletions src/id.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use core::{fmt::Debug, hash};

Expand Down
8 changes: 4 additions & 4 deletions src/key_value_db.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use alloc::collections::BTreeSet;
use alloc::format;
use alloc::string::ToString;
use alloc::vec::Vec;
#[cfg(not(feature = "std"))]
use alloc::{collections::BTreeSet, format, string::ToString, vec::Vec};
use log::trace;
#[cfg(feature = "std")]
use std::collections::BTreeSet;

use crate::{
bonsai_database::{BonsaiDatabase, BonsaiPersistentDatabase, KeyType},
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,11 @@
//! bonsai_storage.commit(id_builder.new_id()).unwrap();
//! ```
#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(not(feature = "std"))]
extern crate alloc;

use crate::trie::merkle_tree::{Membership, MerkleTree, ProofNode};
use crate::trie::merkle_tree::MerkleTree;
#[cfg(not(feature = "std"))]
use alloc::{format, vec::Vec};
use bitvec::{order::Msb0, slice::BitSlice};
use bonsai_database::{BonsaiPersistentDatabase, KeyType};
Expand Down
3 changes: 3 additions & 0 deletions src/tests/proof.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#[cfg(feature = "std")]
use std::collections::HashMap;
#[cfg(not(feature = "std"))]
use {alloc::string::String, hashbrown::HashMap};

use bitvec::vec::BitVec;
use pathfinder_common::{hash::PedersenHash, trie::TrieNode};
Expand Down
10 changes: 4 additions & 6 deletions src/trie/merkle_tree.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use alloc::format;
use alloc::string::ToString;
use alloc::vec;
use alloc::vec::Vec;
#[cfg(not(feature = "std"))]
use alloc::{format, string::ToString, vec, vec::Vec};
use bitvec::{
prelude::{BitSlice, BitVec, Msb0},
view::BitView,
Expand Down Expand Up @@ -1202,7 +1200,7 @@ impl<H: StarkHash, DB: BonsaiDatabase, ID: Id> MerkleTree<H, DB, ID> {
}
}

#[cfg(test)]
#[cfg(all(test, feature = "std"))]
mod tests {
use crate::{
databases::{create_rocks_db, RocksDB, RocksDBConfig},
Expand Down Expand Up @@ -1247,7 +1245,7 @@ mod tests {
}
let madara_elements = elements
.iter()
.map(|felt| madara_felt_from_felt(felt))
.map(madara_felt_from_felt)
.collect::<Vec<_>>();
let rocks_db = create_rocks_db(std::path::Path::new(tempdir.path())).unwrap();
let rocks_db = RocksDB::new(&rocks_db, RocksDBConfig::default());
Expand Down
1 change: 1 addition & 0 deletions src/trie/trie_db.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{bonsai_database::KeyType, changes::ChangeKeyType};
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

#[derive(Debug, Hash, PartialEq, Eq)]
Expand Down

0 comments on commit 73a3a80

Please sign in to comment.