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

feat: use new IterableMap and IterableSet collections #139

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ jobs:
override: true
target: wasm32-unknown-unknown

- uses: Swatinem/rust-cache@v1
- uses: Swatinem/rust-cache@v2
with:
key: rust-version-${{ env.MSRV }}-msrv-2

- name: add wasm32-unknown-unknown
run: rustup target add wasm32-unknown-unknown

- name: cargo test
run: cargo test --all --all-features
run: cargo test --workspace --all-features

lint:
name: Format
Expand All @@ -49,12 +49,12 @@ jobs:
override: true
components: rustfmt, clippy

- uses: Swatinem/rust-cache@v1
- uses: Swatinem/rust-cache@v2
with:
key: rust-version-${{ env.MSRV }}-msrv-2

- name: cargo fmt
run: cargo fmt --all -- --check

- name: cargo clippy
run: cargo clippy --all --all-features --all-targets -- -D warnings
run: cargo clippy --workspace --all-features --all-targets -- -D warnings
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,12 @@ proc-macro2 = "1.0"
quote = "1.0.9"
syn = { version = "1.0.69", features = ["full"] }
proc-macro-crate = "0.1.5"

[workspace.lints.clippy]
all = "deny"
nursery = "deny"
pedantic = "deny"

module_name_repetitions = "allow"
missing_errors_doc = "allow"
missing_panics_doc = "allow"
3 changes: 3 additions & 0 deletions near-plugins-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ near-sdk = { workspace = true, features = ["unit-testing"] }
tokio.workspace = true
near-workspaces.workspace = true
toml.workspace = true

[lints]
workspace = true
20 changes: 10 additions & 10 deletions near-plugins-derive/src/access_control_role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn derive_access_control_role(input: TokenStream) -> TokenStream {
);
let variant_idxs: Vec<_> =
(0..u8::try_from(variant_idents.len()).expect("Too many enum variants")).collect();
let variant_names: Vec<_> = variant_idents.iter().map(|v| format!("{}", v)).collect();
let variant_names: Vec<_> = variant_idents.iter().map(|v| format!("{v}")).collect();

let boundchecker_type = Ident::new(DEFAULT_BOUNDCHECKER_TYPE_NAME, ident.span());
let bitflags_type_ident = new_bitflags_type_ident(Span::call_site());
Expand All @@ -89,7 +89,7 @@ pub fn derive_access_control_role(input: TokenStream) -> TokenStream {
// Without this explicit check, compilation would still fail if a bound
// is not satisfied. Though with less a clear error message.
struct #boundchecker_type<T: Copy + Clone> {
_marker: ::std::marker::PhantomData<T>,
_marker: std::marker::PhantomData<T>,
}
impl<T: Copy + Clone> #boundchecker_type<T> {
fn new() -> Self {
Expand All @@ -113,7 +113,7 @@ pub fn derive_access_control_role(input: TokenStream) -> TokenStream {
}
}

impl ::std::convert::TryFrom<u8> for #ident {
impl std::convert::TryFrom<u8> for #ident {
type Error = &'static str;

fn try_from(value: u8) -> Result<Self, Self::Error> {
Expand Down Expand Up @@ -146,7 +146,7 @@ pub fn derive_access_control_role(input: TokenStream) -> TokenStream {
}
}

impl ::std::convert::TryFrom<&str> for #ident {
impl std::convert::TryFrom<&str> for #ident {
type Error = &'static str;

fn try_from(value: &str) -> Result<#ident, Self::Error> {
Expand All @@ -163,7 +163,7 @@ pub fn derive_access_control_role(input: TokenStream) -> TokenStream {
fn safe_leftshift(value: u128, n: u8) -> u128 {
value
.checked_shl(n.into())
.unwrap_or_else(|| ::near_sdk::env::panic_str("Too many enum variants to be represented by bitflags"))
.unwrap_or_else(|| near_sdk::env::panic_str("Too many enum variants to be represented by bitflags"))
}

impl #cratename::AccessControlRole for #ident {
Expand All @@ -181,15 +181,15 @@ pub fn derive_access_control_role(input: TokenStream) -> TokenStream {
fn acl_permission(self) -> u128 {
// Shift 1u128 left by an odd number, see module documentation.
let n = (u8::from(self) + 1)
.checked_mul(2).unwrap_or_else(|| ::near_sdk::env::panic_str("Too many enum variants")) - 1;
.checked_mul(2).unwrap_or_else(|| near_sdk::env::panic_str("Too many enum variants")) - 1;
safe_leftshift(1, n)
}

fn acl_admin_permission(self) -> u128 {
// Shift 1u128 left by an even number, see module documentation.
let n = (u8::from(self) + 1)
.checked_mul(2)
.unwrap_or_else(|| ::near_sdk::env::panic_str("Too many enum variants"));
.unwrap_or_else(|| near_sdk::env::panic_str("Too many enum variants"));
safe_leftshift(1, n)
}
}
Expand All @@ -198,8 +198,8 @@ pub fn derive_access_control_role(input: TokenStream) -> TokenStream {
/// Encodes permissions for roles and admins.
#[derive(
Default,
::near_sdk::borsh::BorshDeserialize,
::near_sdk::borsh::BorshSerialize,
near_sdk::borsh::BorshDeserialize,
near_sdk::borsh::BorshSerialize,
)]
#[borsh(crate = "near_sdk::borsh")]
struct #bitflags_type_ident: u128 {
Expand Down Expand Up @@ -228,7 +228,7 @@ fn bitflags_idents(names: &[String], span: Span) -> Vec<Ident> {
.collect::<Vec<_>>();
let admin_names = names
.iter()
.map(|name| format!("{}_ADMIN", name))
.map(|name| format!("{name}_ADMIN"))
.collect::<Vec<_>>();
let mut idents = vec![Ident::new(DEFAULT_SUPER_ADMIN_NAME, span)];
for (name, admin_name) in names.iter().zip(admin_names) {
Expand Down
Loading
Loading