String vs &str: Rust's Confusing String Types for Go Devs

    Go to Rust Series: ← Mut vs Immutable | Series Overview | Option and Result → The Confusion Go has one string type: var s string = "hello" Rust has two main string types: let s1: String = String::from("hello"); // Owned string let s2: &str = "hello"; // String slice Why two types? It’s one of the most confusing aspects for Go developers learning Rust. Go: One String Type Go: package main import "fmt" func main() { // All of these are just "string" s1 := "hello" s2 := "world" s3 := s1 + " " + s2 printString(s1) printString(s3) } func printString(s string) { fmt.Println(s) } Simple. Everything is string. ...

    April 26, 2025 · 7 min · Rafiul Alam