rust
fn calculate_length(s: &String) -> usize {
    s.len()
}

fn append_suffix(s: &mut String) {
    s.push_str(" world");

Borrowing with & and &mut for zero-cost access

rust ownership borrowing
by Marcus Chen 1 tab
rust
fn take_ownership(s: String) {
    println!("Took ownership: {}", s);
} // s is dropped here

fn main() {
    let message = String::from("hello");

Ownership transfer prevents double-free and use-after-free

rust ownership memory-safety
by Marcus Chen 1 tab
rust
use anyhow::{Context, Result};
use std::fs;

fn load_config(path: &str) -> Result<String> {
    fs::read_to_string(path)
        .with_context(|| format!("failed to read config from {}", path))

anyhow::Context for adding error context without custom types

rust error-handling cli
by Marcus Chen 1 tab
rust
use thiserror::Error;

#[derive(Error, Debug)]
pub enum ConfigError {
    #[error("file not found: {0}")]
    NotFound(String),

Custom error types with thiserror for domain errors

rust error-handling libraries
by Marcus Chen 1 tab
rust
use std::fs;
use std::num::ParseIntError;

fn read_port(path: &str) -> Result<u16, Box<dyn std::error::Error>> {
    let contents = fs::read_to_string(path)?;
    let port: u16 = contents.trim().parse()?;

Result and ? operator for clean error propagation

rust error-handling
by Marcus Chen 1 tab
ruby
class PostsController < ApplicationController
  def create
    @post = current_user.posts.build(post_params)

    if @post.save
      flash[:success] = 'Post was successfully created.'

Rails Flash messages for user feedback

rails flash messages
by Maya Patel 2 tabs
typescript
import { useEffect, useState, useRef } from 'react'

interface UseInViewOptions {
  threshold?: number | number[]
  rootMargin?: string
  triggerOnce?: boolean

Intersection Observer API for visibility tracking

react performance intersection-observer
by Maya Patel 2 tabs
ruby
module Posts
  class CreateService
    def initialize(author:, params:)
      @author = author
      @params = params
    end

Rails service objects for business logic

rails architecture service-objects
by Maya Patel 2 tabs
typescript
import { useReducer } from 'react'

interface FormState {
  values: Record<string, any>
  errors: Record<string, string>
  touched: Record<string, boolean>

React useReducer for complex state logic

react hooks state-management
by Maya Patel 1 tab
ruby
Rails.application.routes.draw do
  namespace :api do
    namespace :v1 do
      resources :posts do
        resources :comments, only: [:index, :create]
      end

Rails API versioning strategies

rails api versioning
by Maya Patel 3 tabs
typescript
import { useForm } from 'react-hook-form'
import { useState } from 'react'
import api from '@/services/api'

interface SignupFormData {
  email: string

React Hook Form with async validation

react forms validation
by Maya Patel 1 tab
ruby
class SlugValidator < ActiveModel::Validator
  SLUG_REGEX = /\A[a-z0-9]+(?:-[a-z0-9]+)*\z/

  def validate(record)
    slug = record.send(options[:attribute] || :slug)

Rails validators for custom business logic

rails validations activemodel
by Maya Patel 2 tabs