Skip to content

Commit

Permalink
Merge pull request #64 from febo/febo/remove-error-log
Browse files Browse the repository at this point in the history
Remove debug messages
  • Loading branch information
blockiosaurus authored Feb 29, 2024
2 parents f317a22 + 1ae0c27 commit 68d3193
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 36 deletions.
16 changes: 8 additions & 8 deletions shank-idl/src/idl_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl TryFrom<RustType> for IdlType {
}
},
TypeKind::Composite(kind, inners) => match kind {
Composite::Vec => match inners.get(0).cloned() {
Composite::Vec => match inners.first().cloned() {
Some(inner) => {
let inner_idl: IdlType = inner.try_into()?;
if inner_idl == IdlType::U8 {
Expand All @@ -80,7 +80,7 @@ impl TryFrom<RustType> for IdlType {
anyhow::bail!("Rust Vec Composite needs inner type")
}
},
Composite::Array(size) => match inners.get(0).cloned() {
Composite::Array(size) => match inners.first().cloned() {
Some(inner) => {
let inner_idl: IdlType = inner.try_into()?;
IdlType::Array(Box::new(inner_idl), size)
Expand All @@ -90,7 +90,7 @@ impl TryFrom<RustType> for IdlType {
}
},

Composite::Option => match inners.get(0).cloned() {
Composite::Option => match inners.first().cloned() {
Some(inner) => {
let inner_idl: IdlType = inner.try_into()?;
IdlType::Option(Box::new(inner_idl))
Expand All @@ -109,7 +109,7 @@ impl TryFrom<RustType> for IdlType {
}
}
Composite::HashMap => {
match (inners.get(0).cloned(), inners.get(1).cloned()) {
match (inners.first().cloned(), inners.get(1).cloned()) {
(Some(inner1), Some(inner2)) => {
let inner1_idl: IdlType = inner1.try_into()?;
let inner2_idl: IdlType = inner2.try_into()?;
Expand All @@ -126,7 +126,7 @@ impl TryFrom<RustType> for IdlType {
}
}
Composite::BTreeMap => {
match (inners.get(0).cloned(), inners.get(1).cloned()) {
match (inners.first().cloned(), inners.get(1).cloned()) {
(Some(inner1), Some(inner2)) => {
let inner1_idl: IdlType = inner1.try_into()?;
let inner2_idl: IdlType = inner2.try_into()?;
Expand All @@ -142,7 +142,7 @@ impl TryFrom<RustType> for IdlType {
}
}
}
Composite::HashSet => match inners.get(0).cloned() {
Composite::HashSet => match inners.first().cloned() {
Some(inner) => {
let inner_idl: IdlType = inner.try_into()?;
IdlType::HashSet(Box::new(inner_idl))
Expand All @@ -153,7 +153,7 @@ impl TryFrom<RustType> for IdlType {
)
}
},
Composite::BTreeSet => match inners.get(0).cloned() {
Composite::BTreeSet => match inners.first().cloned() {
Some(inner) => {
let inner_idl: IdlType = inner.try_into()?;
IdlType::BTreeSet(Box::new(inner_idl))
Expand Down Expand Up @@ -185,7 +185,7 @@ mod tests {

#[test]
fn idl_from_rust_type_primivives() {
for (rust_prim, idl_expected) in vec![
for (rust_prim, idl_expected) in [
(Primitive::U8, IdlType::U8),
(Primitive::U16, IdlType::U16),
(Primitive::I128, IdlType::I128),
Expand Down
2 changes: 1 addition & 1 deletion shank-macro-impl/src/builder/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl TryFrom<&ParsedEnumVariant> for BuilderVariant {

let field_tys: InstructionVariantFields = if !fields.is_empty() {
// Determine if the InstructionType is tuple or struct variant
let field = fields.get(0).unwrap();
let field = fields.first().unwrap();
match &field.ident {
Some(_) => InstructionVariantFields::Named(
fields
Expand Down
4 changes: 2 additions & 2 deletions shank-macro-impl/src/instruction/idl_instruction_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,14 @@ impl TryFrom<&[Attribute]> for IdlInstruction {
if idl_instructions.len() > 1 {
Err(IdlInstructionError::TooManyIdlInstructions(
ParseError::new_spanned(
attrs.get(0),
attrs.first(),
"Only one #[idl_instruction] attr is allowed per instruction",
),
))
} else if idl_instructions.is_empty() {
Err(IdlInstructionError::NotEnoughIdlInstructions)
} else {
let ix = *idl_instructions.get(0).unwrap();
let ix = *idl_instructions.first().unwrap();
Ok(ix)
}
}
Expand Down
28 changes: 10 additions & 18 deletions shank-macro-impl/src/instruction/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use crate::{
};

use super::{
account_attrs::{InstructionAccount, InstructionAccounts},
IdlInstruction, InstructionStrategies, InstructionStrategy,
account_attrs::InstructionAccount, IdlInstruction, InstructionStrategies,
InstructionStrategy,
};

// -----------------
Expand Down Expand Up @@ -108,7 +108,7 @@ impl TryFrom<&ParsedEnumVariant> for InstructionVariant {

let mut field_tys: InstructionVariantFields = if !fields.is_empty() {
// Determine if the InstructionType is tuple or struct variant
let field = fields.get(0).unwrap();
let field = fields.first().unwrap();
match &field.ident {
Some(_) => InstructionVariantFields::Named(
fields
Expand All @@ -130,24 +130,16 @@ impl TryFrom<&ParsedEnumVariant> for InstructionVariant {
};

let attrs: &[Attribute] = attrs.as_ref();
let accounts: InstructionAccounts;
let strategies: InstructionStrategies;

let idl_instruction = IdlInstruction::try_from(attrs);
match idl_instruction {
let (accounts, strategies) = match IdlInstruction::try_from(attrs) {
Ok(idl_ix) => {
accounts = idl_ix.to_accounts(ident.clone());
field_tys = idl_ix.to_instruction_fields(ident.clone());
strategies = InstructionStrategies(HashSet::<
InstructionStrategy,
>::new());
}
Err(err) => {
println!("{}", err);
accounts = attrs.try_into()?;
strategies = attrs.into();
(
idl_ix.to_accounts(ident.clone()),
InstructionStrategies(HashSet::<InstructionStrategy>::new()),
)
}
}
Err(_) => (attrs.try_into()?, attrs.into()),
};

Ok(Self {
ident: ident.clone(),
Expand Down
4 changes: 2 additions & 2 deletions shank-macro-impl/src/parsed_struct/parsed_struct_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn match_array_field(
assert_eq!(ident, field_ident);
assert_eq!(rust_type.ident, "Array");
assert_matches!(&rust_type.kind, TypeKind::Composite(Composite::Array(array_size), inner) => {
let inner_rust_ty = inner.get(0).expect("array should have inner type");
let inner_rust_ty = inner.first().expect("array should have inner type");
assert_eq!(inner_rust_ty.ident, inner_ty, "inner array type");
assert_eq!(*array_size, size, "array size");
});
Expand All @@ -60,7 +60,7 @@ fn match_array_field_with_attrs(
assert_eq!(ident, field_ident);
assert_eq!(rust_type.ident, "Array");
assert_matches!(&rust_type.kind, TypeKind::Composite(Composite::Array(array_size), inner) => {
let inner_rust_ty = inner.get(0).expect("array should have inner type");
let inner_rust_ty = inner.first().expect("array should have inner type");
assert_eq!(inner_rust_ty.ident, inner_ty, "inner array type");
assert_eq!(*array_size, size, "array size");
});
Expand Down
1 change: 0 additions & 1 deletion shank-macro-impl/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ mod render_rust_ty;
mod resolve_rust_ty;
mod type_kind;
pub use parsed_reference::*;
pub use render_rust_ty::*;
pub use resolve_rust_ty::*;
pub use type_kind::*;
1 change: 0 additions & 1 deletion shank-macro-impl/src/types/resolve_rust_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ pub fn resolve_rust_ty(
}
};

println!("[resolve_rust_ty] {:?}: {:?}", ident, kind);
Ok(RustType {
ident,
kind,
Expand Down
6 changes: 3 additions & 3 deletions shank-macro-impl/src/types/type_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl TypeKind {
| TypeKind::Composite(Composite::Array(_), inners)
| TypeKind::Composite(Composite::HashSet, inners)
| TypeKind::Composite(Composite::BTreeSet, inners) => {
inners.get(0).cloned()
inners.first().cloned()
}
TypeKind::Composite(_, _) => None,
TypeKind::Unit => None,
Expand All @@ -127,7 +127,7 @@ impl TypeKind {
TypeKind::Value(_) => (None, None),
TypeKind::Composite(Composite::HashMap, inners)
| TypeKind::Composite(Composite::BTreeMap, inners) => {
(inners.get(0).cloned(), inners.get(1).cloned())
(inners.first().cloned(), inners.get(1).cloned())
}
TypeKind::Composite(_, _) => (None, None),
TypeKind::Unit => (None, None),
Expand All @@ -144,7 +144,7 @@ impl TypeKind {
|| composite == &Composite::BTreeMap =>
{
let key = inners
.get(0)
.first()
.cloned()
.ok_or_else(|| {
format!("{:?} should have key type", composite)
Expand Down

0 comments on commit 68d3193

Please sign in to comment.