Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Code Style

Code style guidelines for Bindy.

Rust Style

Follow official Rust style guide:

# Format code
cargo fmt

# Check for issues
cargo clippy

Naming Conventions

  • snake_case for functions, variables
  • PascalCase for types, traits
  • SCREAMING_SNAKE_CASE for constants

Documentation

Document public APIs:

#![allow(unused)]
fn main() {
/// Reconciles a Bind9Instance resource.
///
/// Creates or updates Kubernetes resources for BIND9.
///
/// # Arguments
///
/// * `instance` - The Bind9Instance to reconcile
///
/// # Returns
///
/// Ok(()) on success, Err on failure
pub async fn reconcile(instance: Bind9Instance) -> Result<()> {
    // Implementation
}
}

Error Handling

Use anyhow::Result for errors:

#![allow(unused)]
fn main() {
use anyhow::{Context, Result};

fn do_thing() -> Result<()> {
    some_operation()
        .context("Failed to do thing")?;
    Ok(())
}
}

Testing

Write tests for all public functions:

#![allow(unused)]
fn main() {
#[cfg(test)]
mod tests {
    use super::*;
    
    #[test]
    fn test_function() {
        assert_eq!(function(), expected);
    }
}
}