Back to all reviewers

Reuse existing API utilities

unionlabs/union
Based on 3 comments
Rust

Before implementing custom API utilities, serializers, or type identification methods, check if equivalent functionality already exists in the codebase or standard libraries. This prevents code duplication, ensures consistency across the API surface, and leverages well-tested implementations.

API Rust

Reviewer Prompt

Before implementing custom API utilities, serializers, or type identification methods, check if equivalent functionality already exists in the codebase or standard libraries. This prevents code duplication, ensures consistency across the API surface, and leverages well-tested implementations.

Key practices:

  • Search for existing utilities in shared crates before writing custom implementations
  • Use trait-provided methods for standard operations like type identification
  • Verify API feature compatibility with the target environment before usage

Examples from the codebase:

// Instead of custom deserializer:
#[serde(default, deserialize_with = "deserialize_opt_u64_from_string")]
// Use existing utility:
// Available in serde_utils crate

// Instead of hardcoded type URLs:
type_url: "/ibc.applications.transfer.v1.MsgTransfer".to_string(),
// Use trait method:
type_url: MsgTransfer::type_url(),

// Avoid incompatible features:
#[sol(rpc, all_derives)] // Don't use 'rpc' in cosmwasm contracts

This approach reduces maintenance burden, improves code reliability, and maintains API consistency across the project.

3
Comments Analyzed
Rust
Primary Language
API
Category

Source Discussions