ownership

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
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
java
package com.shop.security;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.access.PermissionEvaluator;
import org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler;

Guard a Checkout Endpoint with @PreAuthorize and a Custom PermissionEvaluator in Spring Boot

spring-boot spring-security authorization
by codesnips 3 tabs
php
<?php

namespace App\Security\Voter;

use App\Entity\Comment;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;

Enforce Comment Ownership With a Symfony Voter and Controller Authorization Check

symfony security voter
by codesnips 3 tabs
rust
pub enum Node {
    File { name: String, size: u64 },
    Dir { name: String, children: Vec<Node> },
}

impl Node {

Modeling a Filesystem Tree in Rust with Recursive Enums and Total Size

rust recursion enums
by codesnips 3 tabs
rust
#[derive(Debug, Clone)]
pub enum Outcome {
    Approve,
    Review,
    Reject(String),
}

Modeling and Evaluating a Decision Tree with Recursive Rust Enums

rust enums recursion
by codesnips 3 tabs