<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Bulut Can Gocer on Medium]]></title>
        <description><![CDATA[Stories by Bulut Can Gocer on Medium]]></description>
        <link>https://medium.com/@bulutcangocer0199?source=rss-84bea46bd65c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*4m5owC-FgUI7qDxYX4XXfw.jpeg</url>
            <title>Stories by Bulut Can Gocer on Medium</title>
            <link>https://medium.com/@bulutcangocer0199?source=rss-84bea46bd65c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 13:53:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bulutcangocer0199/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Learning Rust as a Golang Dev — Part 3]]></title>
            <link>https://medium.com/@bulutcangocer0199/learning-rust-as-a-golang-dev-part-3-adb06dc20051?source=rss-84bea46bd65c------2</link>
            <guid isPermaLink="false">https://medium.com/p/adb06dc20051</guid>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[rust-vs-go-performance]]></category>
            <category><![CDATA[rust-programming-language]]></category>
            <dc:creator><![CDATA[Bulut Can Gocer]]></dc:creator>
            <pubDate>Wed, 21 Aug 2024 15:21:24 GMT</pubDate>
            <atom:updated>2024-08-21T15:21:24.993Z</atom:updated>
            <content:encoded><![CDATA[<h3>Learning Rust as a Golang Dev — Part 3</h3><p><strong>Welcome back after a long break, everyone!</strong> This will be the third article in our series. In the previous section, we explored some of the built-in types. Now, we’ll take it a step further and dive into collection types and user-defined types.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*uybc3wvvwnolp_oUo087ww.png" /></figure><h3><strong><em>Collection Types</em></strong></h3><p><strong>Collection Types</strong> are data structures that used for group multiple values together. These helps to manage and manipulate data efficiently, making it easier to work with large datasets or complex data relationships.</p><ol><li><strong>Vec (Vectors)</strong>: A dynamically sized array. Elements are stored contiguously in memory, and you can push new elements onto a <strong>Vec</strong> or pop elements from it.</li></ol><pre>let mut numbers = Vec::new();<br>numbers.push(1);<br>numbers.push(2);<br>numbers.push(3);</pre><p>As you may have noticed, it is very similar to the slice concept in go. Now we will touch on a few differences between them:</p><ul><li><strong>Mutability: </strong>In Rust, Vec can be either mutable or immutable, while Go slices are always mutable.</li><li><strong>Ownership and Borrowing</strong>: Rust enforces ownership rules to prevent data races and memory leaks. If a Vec needs to be used in multiple places, references (&amp;Vec or &amp;mut Vec) are used; whereas in Go, slices are a view over an underlying array and have a capacity (capacity). When the capacity is exceeded during an append operation, Go typically allocates a new array and copies the data over.</li><li><strong>Capacity: </strong>A Vec can have its capacity pre-allocated, which helps in more efficient memory usage. The capacity can grow automatically if needed, but this can trigger a reallocation; but in Go, slices are a view over an underlying array and have a capacity (capacity). When the capacity is exceeded during an append operation, Go typically allocates a new array and copies the data over.</li><li><strong>Memory Management</strong>: Rust’s Vec memory is automatically freed when out of scope, while Go slices rely on garbage collection.</li><li><strong>Concurrency</strong>: Rust ensures Vec mutation safety through strict rules, while Go slices can be accessed concurrently, risking data races.</li></ul><p>2. HashMap: HashMap is a data structure that allows you to store key-value pairs, where each unique key is associated with a value.</p><pre>let mut letters_number = HashMap::new();<br>    letters_number.insert(&quot;a&quot;, 1); <br><br>    if let Some(numb) = letters_number.get(&quot;a&quot;) {<br>        println!(&quot;{}&quot;, numb); <br>    }</pre><p>They’re very similar to map. Just a couple of difference:</p><ul><li><strong>Mutability</strong>: In Rust, HashMap can be mutable or immutable, while in Go, map is always mutable.</li><li><strong>Key/Value Types</strong>: Rust’s HashMap can have any type as key or value, provided the key implements Eq and Hash, while Go’s map keys must be comparable types, and both key and value can be any type.</li></ul><h3>User-Defined Types</h3><ol><li>Struct: Structs in Rust are custom data types that group together related data. They are used to create complex data models and can have associated methods to define behavior.</li></ol><pre>struct Person{<br>name: String,<br>age: u32,<br>}<br><br>struct Color(u8, u8, u8); // Each element can have a different type. <br><br>struct Unit; // It’s similar to the unit type () </pre><p><strong>They’re almost same with Go’s struct. Key differences:</strong></p><ul><li><strong>Zero-Cost Abstractions</strong>: Rust emphasizes zero-cost abstractions, optimizing performance without overhead beyond manual implementations. Yet Go, focuses on simplicity and ease of use, sometimes at the cost of performance efficiency.</li><li><strong>Field Visibility</strong>: In Rust fields are private by default, requiring pub to make them accessible outside the module. But in Go, field visibility is determined by the field name’s case, with uppercase being public and lowercase being private.</li></ul><p>2. Enum (Enumerations): Enums in Rust represent a type that can be one of several different variants, each of which may have associated data. They are useful for modeling situations where a value can take on one of a few different, but known, forms.</p><pre>enum TrafficLight {<br>    Red,<br>    Yellow,<br>    Green,<br>}<br><br>enum Role{<br>Admin,<br>Moderator,<br>User,<br>}</pre><p>Unfortunately, in Go, there isn’t a direct equivalent to enums as seen in Rust language. While we can create structures that resemble enums, we cannot achieve a true equivalent.</p><pre>type Role int<br><br>const (<br>    Admin UserRole = iota<br>    Moderator<br>    User<br>)</pre><p><strong>Common Use Cases of Enums in Rust</strong></p><p>1. Error Handling: Results are commonly used to represent the outcome of operations that can either succeed or fail. The Result type is an enum with two variants:</p><ul><li><strong>Ok(T)</strong>: Represents a successful outcome and contains a value of type T.</li><li><strong>Err(E)</strong>: Represents a failure and contains an error of type E.</li></ul><pre>enum FileError {<br>    NotFound,<br>    PermissionDenied,<br>    Other(String),<br>}<br><br>fn read_file(filename: &amp;str) -&gt; Result&lt;String, FileError&gt; {<br>    if filename == &quot;missing.txt&quot; {<br>        Err(FileError::NotFound)<br>    } else if filename == &quot;forbidden.txt&quot; {<br>        Err(FileError::PermissionDenied)<br>    } else {<br>        Ok(&quot;File content&quot;.to_string())<br>    }<br>}</pre><p>2. Handling Optional Values: Option type is a powerful and commonly used enum that represents a value that can either be present (Some) or absent (None).</p><pre>fn get_user_by_email(user_id: u32) -&gt; Option&lt;String&gt; {<br>let mut email_database: HashMap&lt;u32, String&gt; // Pretend to we have id email map<br> if let Some(email) = email_database.get(&amp;user_id) {<br>        Some(email.clone()) <br>    } else {<br>        None<br>    }<br>}</pre><p>We’ve covered advanced built-in types in Rust and compared them with Go. In the next article, we’ll dive into ‘Ownership’ that is Rust’s most unique feature. Stay tuned!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=adb06dc20051" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learning Rust as a Golang Dev — Part 2]]></title>
            <link>https://medium.com/@bulutcangocer0199/learning-rust-as-a-golang-dev-part-2-495cdc76b846?source=rss-84bea46bd65c------2</link>
            <guid isPermaLink="false">https://medium.com/p/495cdc76b846</guid>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[rust-for-beginners]]></category>
            <dc:creator><![CDATA[Bulut Can Gocer]]></dc:creator>
            <pubDate>Sun, 26 May 2024 14:11:34 GMT</pubDate>
            <atom:updated>2024-08-21T12:00:33.084Z</atom:updated>
            <content:encoded><![CDATA[<h3>Learning Rust as a Golang Dev — Part 2</h3><p>Welcome back, friends! This is the second part of our series, <em>Learning Rust as a Golang Dev</em>. In the previous section, we introduced Rust and my reasons for starting this journey. Now, we’ll delve into the language’s structure and explore some common programming concepts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*uybc3wvvwnolp_oUo087ww.png" /></figure><p>In Rust, variables are immutable by default. This means once a value is bound to a variable, it cannot be changed. To declare a variable, you use the ‘let’ keyword it’s like ‘var’ in Go but not mutable version:</p><pre>let x = 5; <br>let y: i32 = 5;<br>let z = 5_i32;<br>let t = 1i32;</pre><p>If you try to reassign ‘x’ to another value, Rust will throw a compile-time error. However, if you need a mutable variable, you can explicitly mark it with the mut keyword:</p><pre>let mut x = 10;<br>let mut y: i32 = 10;<br>let mut z = 10_i32;<br>let mut t = 1i32;</pre><h3>Built-in Types</h3><h4>Scalar Types</h4><p>Here are some basic built-in types:</p><ul><li><strong>Signed integers -&gt;</strong>i8, i16, i32, i64, i128</li><li><strong>Unsigned integers -&gt;</strong>u8, u16, u32, u64, u128</li><li><strong>Floating numbers -&gt;</strong>f32, f64</li><li><strong>Unicode scalar values -&gt;</strong>char</li><li><strong>Booleans -&gt;</strong>bool</li></ul><p>You might have noticed that we haven’t mentioned a string type that’s because Rust handles strings a bit differently; instead of a single primitive string type like in Go, Rust uses two main string types: &amp;str and String. Instead of a single string type, Rust has two main types for handling text data: &amp;str and String.</p><ul><li><strong>&amp;str (String Slice)</strong> <strong>-&gt; </strong>&amp;str, is a reference to a string. It is typically used to borrow a portion of a string without taking ownership (we will mention it later) of it. String slices are immutable and often used for function parameters where the string data doesn’t need to be modified.</li><li><strong>String</strong> -&gt; This type is a growable, heap-allocated string. Unlike &amp;str, a &#39;String’ can be modified and resized. This is useful when you need to create or modify string data dynamically.</li></ul><p>In Go, strings are immutable sequences of bytes, represented by the string type. They are more similar to Rust’s &amp;str in terms of immutability.</p><h4>Compound Types</h4><ul><li><strong>Tuple</strong> -&gt; Tuples are used to group together a fixed number of values of potentially different types. They are defined using parentheses () and can contain any combination of types and also can access tuple elements by their index. You can do things like this:</li></ul><pre>let tuple_of_tuples = ((1u8, 2u16, 2u32), (4u64, -1i8), -2i16);<br>let x = tuple_of_tuples.0;</pre><ul><li><strong>Array</strong> -&gt; Arrays in Rust have a fixed size and contain elements of the same type. Arrays are useful when you know the number of elements will not need to change. If you need a dynamically sized array in Rust, you should use Vec&lt;T&gt;, which is Rust&#39;s equivalent of Go slices (we&#39;ll discuss Vec&lt;T&gt; in more detail later in the series).</li></ul><pre>let my_array: [i32; 5] = [1, 2, 3, 4, 5];]); <br>let mut another_array = [0; 3]; <br>another_array[0] = 10;</pre><p>We’ve covered built-in types in Rust and compared them with Go. In the next article, we’ll dive into advanced built-in types. Stay tuned for our exploration!</p><p>Resources:<br><a href="https://doc.rust-lang.org/book">https://doc.rust-lang.org/book</a><br><a href="https://doc.rust-lang.org/book">https://</a>doc.rust-lang.org/rust-by-example<br><a href="https://google.github.io/comprehensive-rust">https://google.github.io/comprehensive-rust</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=495cdc76b846" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Let’s Learn Rust as a Golang Dev — Part 1]]></title>
            <link>https://medium.com/@bulutcangocer0199/lets-learn-rust-as-a-golang-dev-part-1-3708f25f5673?source=rss-84bea46bd65c------2</link>
            <guid isPermaLink="false">https://medium.com/p/3708f25f5673</guid>
            <category><![CDATA[rust-for-beginners]]></category>
            <category><![CDATA[rust]]></category>
            <dc:creator><![CDATA[Bulut Can Gocer]]></dc:creator>
            <pubDate>Sat, 25 May 2024 18:13:40 GMT</pubDate>
            <atom:updated>2024-05-25T23:05:29.736Z</atom:updated>
            <content:encoded><![CDATA[<h3>Learning Rust as a Golang Dev — Part 1</h3><p>Hello, everyone! My name is Bulut, and I’m a Golang developer who has recently embarked on a journey to learn Rust. As a Go developer, I’ve found Rust to be both fascinating and challenging, and I want to share my learning experience with you through this series of articles.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*uybc3wvvwnolp_oUo087ww.png" /></figure><p>In this series, we will explore the Rust language from the perspective of a Golang developer. This approach will provide insights into Rust from the viewpoint of someone new to the language and also serve as a personal reference. We’ll cover the basics, delve into advanced topics, and compare Rust’s features with those of Go. By the end of this journey, I hope you’ll have a solid understanding of Rust and be able to decide when and why to use it. So let’s start.</p><h3>Overview of Rust</h3><p>Rust is a systems programming language that runs blazingly fast, prevents segfaults, and guarantees thread safety. It was designed by Mozilla and has gained significant traction in the developer community due to its focus on safety and performance. Additionally, it has become the most loved language on Stack Overflow for several years.</p><h3>Why I started to Rust?</h3><p>Learning Rust provides me with significant advantages to expand my skills as a Go developer. Rust stands out for its performance and memory safety; its ownership system prevents memory management errors while delivering high performance without needing a garbage collector like Go. Rust’s concurrency model detects data races at compile time, making concurrent programming safer and easier. As a Go developer fascinated by concurrency, I’m intrigued by Rust’s reputation for performance and safety. I’m eager to explore its innovative concurrency model, which promises fearless concurrency with compile-time detection of data races. By diving into Rust’s ecosystem, known for its strengths in system programming and game development, I hope to broaden my skills and potentially unlock new opportunities for my projects and career.</p><h3>Resources that i use for learning Rust</h3><p>When I searched for Rust learning resources, I found some widely accepted ones. “The Rust Programming Language” serves as a foundational guide, while “Rust by Example” offers hands-on learning through practical examples. For a deeper dive into specific topics, I turn to “Programming Rust,” enriching my understanding and adapting my approach as needed.</p><h3>So finally first program</h3><p>Let’s start by typing “Hello world” into the terminal, a favorite of everyone.</p><pre>println!(&quot;Hello, world!&quot;);</pre><p>In Rust, when you want to print something to the console, you use the println! ‘macro’. It&#39;s like a special command that helps you show stuff on the screen. For example, if you want to say &quot;Hello, world!&quot; you&#39;d write &quot;println!(&quot;Hello, world!&quot;);&quot;. In Go, instead of a macro, you use a function called fmt.Println. It works a bit like println! in Rust, but it&#39;s written a little differently. So in Go, you&#39;d say “fmt.Println(&quot;Hello, world!&quot;)”. They both do the same thing—print stuff to the screen.</p><p>We’ve just showcased how to use println! with a Rust example. In the next topic, we’ll dive into common programming concepts. See you there!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3708f25f5673" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>