<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Son DotCom 🥑💙</title>
    <description>The latest articles on DEV Community by Son DotCom 🥑💙 (@charles_lukes).</description>
    <link>https://dev.to/charles_lukes</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F288507%2F10a73de7-1753-43f3-8be0-c8c425a3d75f.png</url>
      <title>DEV Community: Son DotCom 🥑💙</title>
      <link>https://dev.to/charles_lukes</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/charles_lukes"/>
    <language>en</language>
    <item>
      <title>Understanding AI Agents: How Agentic Systems Actually Work</title>
      <dc:creator>Son DotCom 🥑💙</dc:creator>
      <pubDate>Tue, 20 Jan 2026 16:51:40 +0000</pubDate>
      <link>https://dev.to/charles_lukes/understanding-ai-agents-how-agentic-systems-actually-work-3jhj</link>
      <guid>https://dev.to/charles_lukes/understanding-ai-agents-how-agentic-systems-actually-work-3jhj</guid>
      <description>&lt;p&gt;AI is no longer an experiment or a buzzword as it is becoming core infrastructure for how modern software is built and operated.&lt;/p&gt;

&lt;p&gt;As AI systems evolve from passive tools into systems that can reason, act, and make decisions, new terms like &lt;em&gt;AI agents&lt;/em&gt; are appearing everywhere. Unfortunately, many of these terms are poorly defined and widely misunderstood.&lt;/p&gt;

&lt;p&gt;This article aims to fix that.&lt;/p&gt;

&lt;p&gt;We’ll start by clarifying what AI actually is, then build up to a clear and practical understanding of AI agents, how they work, what makes them different, and why they matter.&lt;/p&gt;

&lt;h2&gt;
  
  
  WHAT IS AI
&lt;/h2&gt;

&lt;p&gt;According to &lt;a href="https://www.ibm.com/think/topics/artificial-intelligence" rel="noopener noreferrer"&gt;IBM&lt;/a&gt;, Artificial Intelligence (AI) refers to technology that enables computers and machines to simulate human learning, comprehension, problem-solving, decision-making, creativity, and autonomy.&lt;/p&gt;

&lt;p&gt;At its core, AI is not magical. It is a system that works by learning patterns from data, data created and accumulated by humans over time and using those patterns to make predictions, decisions, or generate outputs.&lt;/p&gt;

&lt;p&gt;The “intelligence” we observe in AI systems is the result of mathematical models, data, and optimization techniques not consciousness, intent, or awareness.&lt;/p&gt;

&lt;p&gt;While there are many forms of AI, most practical systems fall into a few key categories.&lt;/p&gt;

&lt;h3&gt;
  
  
  Rule-Based Systems
&lt;/h3&gt;

&lt;p&gt;Rule-based systems are the simplest form of AI. They operate entirely on predefined rules written by humans.&lt;/p&gt;

&lt;p&gt;They do not learn.&lt;br&gt;
They do not adapt.&lt;br&gt;
They only follow instructions.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;IF the warehouse light is turned on -&amp;gt; say "HELLO"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These systems are predictable and reliable, but extremely limited.&lt;/p&gt;

&lt;h3&gt;
  
  
  Machine Learning Systems
&lt;/h3&gt;

&lt;p&gt;Machine learning systems differ from rule-based systems in one important way:&lt;br&gt;
they learn patterns from data instead of relying solely on hand-written rules.&lt;/p&gt;

&lt;p&gt;Rather than explicitly telling the system what to do, we allow it to observe behavior and infer patterns.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When is the light turned on today?&lt;/li&gt;
&lt;li&gt;When is it turned off?&lt;/li&gt;
&lt;li&gt;What about the last 7 days?&lt;/li&gt;
&lt;li&gt;What patterns emerge?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Result:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Light turns on around 7:30 AM&lt;/li&gt;
&lt;li&gt;Light turns off around 8:00 PM&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;From this learned pattern, the system can now make a recommendation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;IF light is turned on around 7:30 AM -&amp;gt; say "Hello, Good morning"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At its core its not understanding rather it is pattern recognition based on data.&lt;/p&gt;

&lt;h3&gt;
  
  
  Large Language Models (LLMs)
&lt;/h3&gt;

&lt;p&gt;Large Language Models are a specific type of machine learning system trained on massive amounts of text data.&lt;/p&gt;

&lt;p&gt;They learn how language works by predicting the next token (piece of text) in a sequence, based on the context provided so far.&lt;/p&gt;

&lt;p&gt;Despite how human-like they may appear, LLMs do not think or understand in the way humans do. Their outputs are driven by probability, context, and learned patterns not intent or awareness.&lt;/p&gt;

&lt;p&gt;What makes LLMs powerful is their ability to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;reason over large contexts&lt;/li&gt;
&lt;li&gt;generate structured outputs&lt;/li&gt;
&lt;li&gt;adapt responses based on prior information&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This idea of context is important, we’ll return to it shortly.&lt;/p&gt;

&lt;p&gt;By default, an LLM is stateless, it has no memory unless one is deliberately provided.&lt;/p&gt;

&lt;p&gt;Now that we have a clear understanding of what AI is, we can move forward and examine how AI agents emerge from these systems.&lt;/p&gt;

&lt;h2&gt;
  
  
  AI AGENTS (AGENTIC AI)
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7o181dus8xbs1qiz4zxd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7o181dus8xbs1qiz4zxd.png" alt=" " width="800" height="800"&gt;&lt;/a&gt;&lt;br&gt;
AI agents are one of the main reasons AI adoption has accelerated so quickly in recent years. They represent a shift from AI as a passive tool to AI as an active system that can operate toward a goal.&lt;/p&gt;

&lt;p&gt;Importantly, AI agents do not give AI “human-like thinking.” Instead, they give AI the &lt;em&gt;ability to act&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;An AI agent is a system that can run autonomously, often continuously, and perform tasks on behalf of a user by deciding what actions to take and which tools to use. Rather than responding once and stopping, an agent operates in a loop, observing its environment, making decisions, taking actions, and updating its state until a goal is achieved.&lt;/p&gt;

&lt;p&gt;This is what removes one of the biggest limitations of traditional AI systems.&lt;/p&gt;

&lt;p&gt;Most AI systems are reactive: they wait for input, produce output, and stop.&lt;br&gt;&lt;br&gt;
AI agents, on the other hand, are &lt;strong&gt;goal-driven&lt;/strong&gt;. They can plan, execute workflows, and adapt based on feedback, often without constant user intervention.&lt;/p&gt;

&lt;p&gt;In simple terms, an AI agent is a &lt;strong&gt;continuous autonomous loop&lt;/strong&gt; that works toward a defined objective.&lt;/p&gt;

&lt;p&gt;At a high level, every AI agent is composed of three core building blocks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The AI Model&lt;/strong&gt; =&amp;gt; the decision-making engine (the brain)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Tools&lt;/strong&gt; =&amp;gt; the mechanisms for interacting with the world (the hands)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Orchestrator&lt;/strong&gt; =&amp;gt; the system that manages control flow, state, and execution (the nervous system)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We’ll break down each of these components in detail.&lt;/p&gt;

&lt;h3&gt;
  
  
  The AI Model (The Brain)
&lt;/h3&gt;

&lt;p&gt;The AI model is the core decision-making component of an AI agent. As discussed earlier, it is the same AI system on its own which is a standalone model with no inherent awareness of the environment it operates in.&lt;/p&gt;

&lt;p&gt;An AI model does not see files, understand systems, or know what is happening around it unless that information is explicitly provided. It only works with the input it receives and the context made available to it.&lt;/p&gt;

&lt;p&gt;Modern AI models are trained on massive amounts of data and are capable of producing highly accurate outputs across a wide range of tasks. However, this capability is entirely dependent on the quality and completeness of the context they are given.&lt;/p&gt;

&lt;p&gt;This is why &lt;strong&gt;context is critical&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For an AI agent to behave reliably, the model must be supplied with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;the current state of the system&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;relevant history or memory&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;clear goals and constraints&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Without sufficient context, the model can only guess.&lt;br&gt;&lt;br&gt;
With proper context, it can make informed decisions and select appropriate actions.&lt;/p&gt;

&lt;p&gt;In practice, providing rich and accurate context is one of the most important steps in building a robust AI agent workflow.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example: Language Learning Agent
&lt;/h3&gt;

&lt;p&gt;Imagine we are building a product that helps users learn Portuguese.&lt;/p&gt;

&lt;p&gt;To create an effective AI agent workflow, the AI model (LLM) must be provided with detailed and relevant context about each user. This context is typically collected during onboarding and updated over time as the user progresses.&lt;/p&gt;

&lt;p&gt;Some useful contextual information might include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User’s primary language&lt;/li&gt;
&lt;li&gt;Whether the user has any prior experience with Portuguese or similar languages (e.g. Spanish)&lt;/li&gt;
&lt;li&gt;User type (student, professional, married, etc.)&lt;/li&gt;
&lt;li&gt;User age (to adjust explanations vs. direct instruction)&lt;/li&gt;
&lt;li&gt;Whether the user is a polyglot (has learned multiple languages before)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, consider a new user entering the system.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Current State of the System
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;User is a first-time user&lt;/li&gt;
&lt;li&gt;No lessons completed&lt;/li&gt;
&lt;li&gt;No progress history&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2. Relevant History or Memory
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Primary language: English
&lt;/li&gt;
&lt;li&gt;No prior experience with Portuguese
&lt;/li&gt;
&lt;li&gt;Familiar with Spanish: No
&lt;/li&gt;
&lt;li&gt;Age: 35
&lt;/li&gt;
&lt;li&gt;User type: Married professional
&lt;/li&gt;
&lt;li&gt;Not a polyglot
&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  3. Goals and Constraints
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Goal:&lt;/strong&gt; Help the user build basic conversational Portuguese from scratch&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Constraints:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Avoid assuming prior language knowledge&lt;/li&gt;
&lt;li&gt;Use clear explanations before introducing grammar rules&lt;/li&gt;
&lt;li&gt;Progress at a beginner-friendly pace&lt;/li&gt;
&lt;li&gt;Prefer practical, real-life examples over abstract theory&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;With this context, the AI model is no longer guessing.&lt;br&gt;&lt;br&gt;
It can now decide &lt;em&gt;how&lt;/em&gt; to teach, &lt;em&gt;what&lt;/em&gt; to teach next, and &lt;em&gt;how fast&lt;/em&gt; to move all without being explicitly instructed at every step.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Tools (The Hands)
&lt;/h3&gt;

&lt;p&gt;While the AI model decides &lt;em&gt;what should be done&lt;/em&gt;, tools are what actually &lt;strong&gt;do the work&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In an agentic system, tools are the mechanisms that allow an AI agent to interact with its environment. They execute actions based on the model’s decisions and have access to parts of the system the model itself cannot see or manipulate directly.&lt;/p&gt;

&lt;p&gt;Most tools are backend executors. They can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;read and write files&lt;/li&gt;
&lt;li&gt;fetch or store data&lt;/li&gt;
&lt;li&gt;call APIs&lt;/li&gt;
&lt;li&gt;generate documents&lt;/li&gt;
&lt;li&gt;trigger workflows&lt;/li&gt;
&lt;li&gt;send notifications or updates to users&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The AI model produces structured decisions or instructions, but it is the tools that turn those decisions into real-world effects.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example: Tools in a Language Learning Agent
&lt;/h3&gt;

&lt;p&gt;Continuing with the Portuguese learning app example, the AI model might decide:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;what lesson to present next&lt;/li&gt;
&lt;li&gt;how difficult the explanation should be&lt;/li&gt;
&lt;li&gt;whether the user needs an example, exercise, or review&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The tools then execute these decisions by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;rendering lesson content in the UI&lt;/li&gt;
&lt;li&gt;generating personalized exercises&lt;/li&gt;
&lt;li&gt;storing progress in the database&lt;/li&gt;
&lt;li&gt;creating a tailored study plan&lt;/li&gt;
&lt;li&gt;generating a Notion document or downloadable guide for the user&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this setup, the AI model never directly modifies files, databases, or user interfaces.&lt;br&gt;&lt;br&gt;
It outputs decisions.&lt;br&gt;&lt;br&gt;
The tools carry them out.&lt;/p&gt;

&lt;h4&gt;
  
  
  A key principle
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Tools do not think.
&lt;/li&gt;
&lt;li&gt;They do not reason.
&lt;/li&gt;
&lt;li&gt;They only execute.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This separation is intentional and critical.&lt;/p&gt;

&lt;p&gt;By keeping decision-making (the model) separate from execution (the tools), agent systems become:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;safer&lt;/li&gt;
&lt;li&gt;easier to debug&lt;/li&gt;
&lt;li&gt;easier to extend&lt;/li&gt;
&lt;li&gt;easier to control&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;strong&gt;AI model&lt;/strong&gt; chooses &lt;em&gt;what&lt;/em&gt; to do.&lt;br&gt;&lt;br&gt;
The &lt;strong&gt;tools&lt;/strong&gt; define &lt;em&gt;what is possible&lt;/em&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Orchestrator (The Nervous System)
&lt;/h3&gt;

&lt;p&gt;If the AI model decides &lt;em&gt;what should be done&lt;/em&gt; and the tools &lt;em&gt;do the work&lt;/em&gt;, the orchestrator is what &lt;strong&gt;connects everything together&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The orchestrator is responsible for managing the agent’s control flow. It decides when the model should think, when tools should run, how results are evaluated, and whether the agent should continue, adjust, or stop.&lt;/p&gt;

&lt;p&gt;After a tool executes an action, the orchestrator:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;inspects the result&lt;/li&gt;
&lt;li&gt;compares it against the user’s goal&lt;/li&gt;
&lt;li&gt;determines whether the outcome is satisfactory&lt;/li&gt;
&lt;li&gt;identifies errors or gaps&lt;/li&gt;
&lt;li&gt;feeds updated context back to the AI model&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This loop is what gives an AI agent its sense of continuity and progress.&lt;/p&gt;

&lt;p&gt;Because of this, the orchestrator is the &lt;em&gt;heart&lt;/em&gt; of an AI agent.&lt;br&gt;&lt;br&gt;
A powerful model with a weak orchestrator will behave inconsistently, repeat mistakes, or fail silently. A well-designed orchestrator, even with a modest model, can produce reliable and predictable behavior.&lt;/p&gt;

&lt;h3&gt;
  
  
  What the Orchestrator Actually Does
&lt;/h3&gt;

&lt;p&gt;In practice, the orchestrator is responsible for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;managing the observe =&amp;gt; decide =&amp;gt; act =&amp;gt; evaluate loop&lt;/li&gt;
&lt;li&gt;handling retries and failures&lt;/li&gt;
&lt;li&gt;enforcing constraints and stopping conditions&lt;/li&gt;
&lt;li&gt;updating memory and historical context&lt;/li&gt;
&lt;li&gt;determining what the model sees next&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is also where learning at the &lt;em&gt;system level&lt;/em&gt; happens.&lt;br&gt;&lt;br&gt;
Not learning in the sense of retraining the model, but learning in how context, preferences, and outcomes are accumulated over time.&lt;/p&gt;

&lt;p&gt;What ultimately differentiates one AI agent from another is not the model it uses, but &lt;strong&gt;how well its orchestrator manages this loop&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example: Orchestration in a Language Learning Agent
&lt;/h3&gt;

&lt;p&gt;Continuing with the Portuguese learning app example:&lt;/p&gt;

&lt;p&gt;Assume the user provides feedback after the first lesson and indicates that they prefer responses delivered with a core Portuguese speaking accent.&lt;/p&gt;

&lt;p&gt;The AI model does not update this preference on its own.&lt;br&gt;&lt;br&gt;
The tool does not understand user intent.  &lt;/p&gt;

&lt;p&gt;It is the orchestrator that captures this feedback and updates the agent’s historical context so future decisions reflect this preference.&lt;/p&gt;

&lt;p&gt;After receiving the feedback, the orchestrator updates the agent state as follows:&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Current State of the System
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;User is not a first-time user&lt;/li&gt;
&lt;li&gt;One lesson completed&lt;/li&gt;
&lt;li&gt;Feedback received on lesson delivery style&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2. Relevant History or Memory
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Primary language: English
&lt;/li&gt;
&lt;li&gt;No prior experience with Portuguese
&lt;/li&gt;
&lt;li&gt;Familiar with Spanish: No
&lt;/li&gt;
&lt;li&gt;Age: 35
&lt;/li&gt;
&lt;li&gt;User type: Married professional
&lt;/li&gt;
&lt;li&gt;Not a polyglot
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Prefers responses delivered with a core Portuguese accent&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  3. Goals and Constraints
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Goal:&lt;/strong&gt; Deliver future lessons using a core Portuguese speaking accent&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Constraints:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Avoid assuming prior language knowledge&lt;/li&gt;
&lt;li&gt;Use clear explanations before introducing grammar rules&lt;/li&gt;
&lt;li&gt;Progress at a beginner-friendly pace&lt;/li&gt;
&lt;li&gt;Prefer practical, real-life examples over abstract theory&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;With this updated context, the next time the AI model is invoked, it does not need to be re-instructed.&lt;br&gt;&lt;br&gt;
The orchestrator ensures the preference is consistently applied across future interactions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bringing It All Together: How AI Agents Actually Work
&lt;/h2&gt;

&lt;p&gt;An AI agent is not a single piece of intelligence. It is a &lt;strong&gt;system&lt;/strong&gt; composed of distinct parts, each with a clear responsibility.&lt;/p&gt;

&lt;p&gt;When these parts are combined correctly, they form a continuous loop that allows the agent to operate autonomously, adapt over time, and reliably work toward a goal.&lt;/p&gt;

&lt;p&gt;At a high level, the flow looks like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The Orchestrator observes the current state&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
It gathers context: user data, system state, memory, and goals.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The AI Model decides what to do next&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Using the provided context, the model reasons and produces a structured decision or plan.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The Tools execute the decision&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Tools interact with the environment, updating data, generating content, calling APIs, or triggering workflows.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The Orchestrator evaluates the outcome&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
It checks whether the action moved the system closer to the goal, identifies errors or feedback, and updates memory.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The loop repeats&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
With updated context, the agent continues until the goal is met or a stopping condition is reached.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This loop is what transforms AI from a reactive system into an agentic one.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to think of it
&lt;/h3&gt;

&lt;p&gt;You can think of an AI agent like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The AI Model&lt;/strong&gt; decides &lt;em&gt;what should happen&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Tools&lt;/strong&gt; make it &lt;em&gt;actually happen&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Orchestrator&lt;/strong&gt; decides &lt;em&gt;when to think, when to act, and when to stop&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;None of these components are sufficient on their own.&lt;/p&gt;

&lt;p&gt;A powerful model without tools cannot act.&lt;br&gt;&lt;br&gt;
Tools without orchestration become brittle automation.&lt;br&gt;&lt;br&gt;
An orchestrator without a reliable model has nothing useful to execute.&lt;/p&gt;

&lt;p&gt;It is the &lt;strong&gt;coordination between all three&lt;/strong&gt; that creates a real AI agent.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why This Is Important
&lt;/h3&gt;

&lt;p&gt;As AI systems continue to evolve, the model itself will become less of a differentiator. Models will improve, commoditize, and be swapped out over time.&lt;/p&gt;

&lt;p&gt;What will matter more is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;how well context is constructed&lt;/li&gt;
&lt;li&gt;how safely tools are exposed&lt;/li&gt;
&lt;li&gt;how intelligently the orchestration loop is designed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In practice, the quality of an AI agent is determined less by how “smart” the model is, and more by how well the system around it is engineered.&lt;/p&gt;

&lt;h3&gt;
  
  
  Finally
&lt;/h3&gt;

&lt;p&gt;AI agents are not intelligent beings.&lt;br&gt;&lt;br&gt;
They are disciplined systems.&lt;/p&gt;

&lt;p&gt;They work because they:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;operate in loops&lt;/li&gt;
&lt;li&gt;act under constraints&lt;/li&gt;
&lt;li&gt;learn from feedback&lt;/li&gt;
&lt;li&gt;and are carefully orchestrated&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you’re currently building AI agents, focus less on swapping models and more on improving how context is constructed, tools are scoped, and orchestration is designed. That’s where most real-world failures and breakthroughs happen.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>ai</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Rust for Solana – EP04: Structs, Enums, Functions, Traits &amp; Modules</title>
      <dc:creator>Son DotCom 🥑💙</dc:creator>
      <pubDate>Thu, 03 Jul 2025 16:27:21 +0000</pubDate>
      <link>https://dev.to/charles_lukes/rust-for-solana-ep04-structs-enums-functions-traits-modules-22np</link>
      <guid>https://dev.to/charles_lukes/rust-for-solana-ep04-structs-enums-functions-traits-modules-22np</guid>
      <description>&lt;p&gt;Now that you understand the &lt;strong&gt;ownership model&lt;/strong&gt; and &lt;strong&gt;data types&lt;/strong&gt; in Rust, it's time to go deeper into how Rust lets us &lt;strong&gt;organize&lt;/strong&gt;, &lt;strong&gt;abstract&lt;/strong&gt;, and &lt;strong&gt;structure&lt;/strong&gt; logic.&lt;/p&gt;

&lt;p&gt;In this episode, you’ll learn:&lt;/p&gt;

&lt;p&gt;✅ How to define and use &lt;strong&gt;structs&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
✅ How to model data with &lt;strong&gt;enums&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
✅ How to apply &lt;strong&gt;pattern matching&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
✅ How to write &lt;strong&gt;functions&lt;/strong&gt; and &lt;strong&gt;traits&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
✅ How to organize your code with &lt;strong&gt;modules&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;These tools are the foundation for building scalable Solana smart contracts and apps in Rust.&lt;/p&gt;


&lt;h2&gt;
  
  
  🧱 Part 1: Structs in Rust
&lt;/h2&gt;

&lt;p&gt;A &lt;code&gt;struct&lt;/code&gt; in Rust is used to group related data.&lt;/p&gt;
&lt;h3&gt;
  
  
  ✨ Defining and Instantiating Structs
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nn"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"alice"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"User: {} is {} years old"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="py"&gt;.username&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="py"&gt;.age&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  ✨ Struct with Associated Function
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;impl&lt;/span&gt; &lt;span class="n"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;is_adult&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.age&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  🔀 Part 2: Enums in Rust
&lt;/h2&gt;

&lt;p&gt;Enums allow you to define a type by enumerating possible &lt;strong&gt;variants&lt;/strong&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  ✨ Example: Message Enum
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;enum&lt;/span&gt; &lt;span class="n"&gt;Message&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Quit&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;Move&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;i32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;i32&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="nf"&gt;Write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Each variant can carry &lt;strong&gt;data&lt;/strong&gt; or none at all.&lt;/p&gt;
&lt;h3&gt;
  
  
  ✨ Matching Enums
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;process&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;match&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nn"&gt;Message&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Quit&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Quit"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="nn"&gt;Message&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Move&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Move to ({x}, {y})"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="nn"&gt;Message&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;Write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Write: {text}"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Enums are powerful for representing &lt;strong&gt;state&lt;/strong&gt;, &lt;strong&gt;commands&lt;/strong&gt;, or &lt;strong&gt;network messages&lt;/strong&gt; — perfect for smart contracts.&lt;/p&gt;


&lt;h2&gt;
  
  
  🎭 Part 3: Pattern Matching
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;match&lt;/code&gt; lets you run code based on pattern logic. It works with enums, primitives, tuples, structs, and more.&lt;/p&gt;
&lt;h3&gt;
  
  
  ✨ Match with &lt;code&gt;Option&amp;lt;T&amp;gt;&lt;/code&gt;
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;maybe_double&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Option&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;i32&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;i32&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;match&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nb"&gt;None&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  ✨ Match with Structs
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Bob"&lt;/span&gt;&lt;span class="nf"&gt;.into&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;match&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;..&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Adult"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Minor"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You can destructure values inside &lt;code&gt;match&lt;/code&gt;, &lt;code&gt;if let&lt;/code&gt;, and &lt;code&gt;while let&lt;/code&gt; for expressive flow control.&lt;/p&gt;


&lt;h2&gt;
  
  
  🧮 Part 4: Functions in Rust
&lt;/h2&gt;

&lt;p&gt;Functions are reusable blocks of code defined using the &lt;code&gt;fn&lt;/code&gt; keyword.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;format!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello, {name}!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  ✨ Key Points
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;All parameters must have types.&lt;/li&gt;
&lt;li&gt;Return type is defined using &lt;code&gt;-&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The last expression (without a &lt;code&gt;;&lt;/code&gt;) is returned.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;i32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;i32&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;i32&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🔌 Part 5: Traits in Rust
&lt;/h2&gt;

&lt;p&gt;Traits define &lt;strong&gt;shared behavior&lt;/strong&gt; that types can implement.&lt;/p&gt;

&lt;h3&gt;
  
  
  ✨ Define a Trait
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;trait&lt;/span&gt; &lt;span class="n"&gt;Summary&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;summarize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  ✨ Implement for Struct
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;impl&lt;/span&gt; &lt;span class="n"&gt;Summary&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;summarize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nd"&gt;format!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{} ({})"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.username&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.age&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  ✨ Use Traits in Functions
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;notify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;impl&lt;/span&gt; &lt;span class="n"&gt;Summary&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Notification: {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="nf"&gt;.summarize&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Traits give Rust powerful &lt;strong&gt;polymorphism&lt;/strong&gt; without runtime overhead.&lt;/p&gt;




&lt;h2&gt;
  
  
  📦 Part 6: Modules in Rust
&lt;/h2&gt;

&lt;p&gt;Modules let you split your code into organized files and control visibility.&lt;/p&gt;

&lt;h3&gt;
  
  
  ✨ Inline Module
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;mod&lt;/span&gt; &lt;span class="n"&gt;greetings&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello!"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nn"&gt;greetings&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  ✨ File-based Modules
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;src/
├── main.rs
└── utils.rs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;main.rs&lt;/code&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;mod&lt;/span&gt; &lt;span class="n"&gt;utils&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nn"&gt;utils&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;welcome&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;utils.rs&lt;/code&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;welcome&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Welcome to Rust for Solana!"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  📚 Summary Table
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Concept&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;struct&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Group related data into one logical unit&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;enum&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Represent multiple related variants&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;match&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Exhaustive pattern matching for control flow&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;fn&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Reusable functions with static typing&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;trait&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Define and share behavior across types&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;mod&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Organize and encapsulate logic across files&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  🧪 Practice Exercises
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Define a Struct
&lt;/h3&gt;

&lt;p&gt;Create a struct &lt;code&gt;Product&lt;/code&gt; with &lt;code&gt;name&lt;/code&gt;, &lt;code&gt;price&lt;/code&gt;, and &lt;code&gt;stock&lt;/code&gt;. Implement a method &lt;code&gt;is_in_stock()&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Enum Challenge
&lt;/h3&gt;

&lt;p&gt;Create an enum &lt;code&gt;OrderStatus&lt;/code&gt; with &lt;code&gt;Pending&lt;/code&gt;, &lt;code&gt;Shipped&lt;/code&gt;, &lt;code&gt;Delivered&lt;/code&gt;. Match and print their status.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Trait Implementation
&lt;/h3&gt;

&lt;p&gt;Define a &lt;code&gt;Displayable&lt;/code&gt; trait with &lt;code&gt;display(&amp;amp;self) -&amp;gt; String&lt;/code&gt;. Implement it for &lt;code&gt;Product&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Module Exercise
&lt;/h3&gt;

&lt;p&gt;Create a &lt;code&gt;math&lt;/code&gt; module with &lt;code&gt;add&lt;/code&gt;, &lt;code&gt;subtract&lt;/code&gt;, &lt;code&gt;multiply&lt;/code&gt;, and &lt;code&gt;divide&lt;/code&gt; functions. Use them in &lt;code&gt;main&lt;/code&gt;.&lt;/p&gt;

</description>
      <category>rust</category>
      <category>solana</category>
      <category>programming</category>
      <category>web3</category>
    </item>
    <item>
      <title>📘EP01 - Intro to Rust and Solana Dev Setup</title>
      <dc:creator>Son DotCom 🥑💙</dc:creator>
      <pubDate>Tue, 24 Jun 2025 15:30:23 +0000</pubDate>
      <link>https://dev.to/charles_lukes/ep01-intro-to-rust-and-solana-dev-setup-373</link>
      <guid>https://dev.to/charles_lukes/ep01-intro-to-rust-and-solana-dev-setup-373</guid>
      <description>&lt;p&gt;Welcome to the first episode of our Rust for Solana Bootcamp — a hands-on journey to becoming a smart contract engineer on Solana using Rust. In this class, we’ll explore why Rust is the language of choice for Solana, and walk through the complete environment setup to get you building on the blockchain&lt;/p&gt;

&lt;p&gt;Today, we’re starting with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Why Rust is the go-to language for Solana development&lt;/li&gt;
&lt;li&gt;How to set up your development environment&lt;/li&gt;
&lt;li&gt;Your first Rust CLI app&lt;/li&gt;
&lt;li&gt;A bonus intro to Anchor&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧠 Why Rust for Solana?
&lt;/h2&gt;

&lt;p&gt;Solana is one of the fastest blockchains — boasting over 65,000 TPS — and it's &lt;strong&gt;written entirely in Rust&lt;/strong&gt;. Here's why Rust is perfect for the job:&lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ Performance &amp;amp; Safety
&lt;/h3&gt;

&lt;p&gt;Rust guarantees memory safety at compile time, with no garbage collector, allowing you to write &lt;strong&gt;blazing fast and reliable code&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ Precise Control
&lt;/h3&gt;

&lt;p&gt;With its ownership and borrowing model, Rust gives you precise control over your memory layout — a must for writing smart contracts.&lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ No Runtime Crashes
&lt;/h3&gt;

&lt;p&gt;Rust’s compiler catches nulls, uninitialized variables, and data races &lt;em&gt;before&lt;/em&gt; they happen.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧰 Prerequisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A machine running &lt;strong&gt;Linux&lt;/strong&gt;, &lt;strong&gt;macOS&lt;/strong&gt;, or &lt;strong&gt;WSL&lt;/strong&gt; (Windows Subsystem for Linux)&lt;/li&gt;
&lt;li&gt;Familiarity with any programming language&lt;/li&gt;
&lt;li&gt;Curiosity and willingness to learn 💪&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔧 Step-by-Step Setup for Rust + Solana Dev
&lt;/h2&gt;

&lt;h3&gt;
  
  
  🟠 1. Install Rust + Cargo
&lt;/h3&gt;

&lt;p&gt;Run this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;--proto&lt;/span&gt; &lt;span class="s1"&gt;'=https'&lt;/span&gt; &lt;span class="nt"&gt;--tlsv1&lt;/span&gt;.2 &lt;span class="nt"&gt;-sSf&lt;/span&gt; https://sh.rustup.rs | sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check that Rust is installed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;rustc &lt;span class="nt"&gt;--version&lt;/span&gt;
cargo &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;✅ &lt;code&gt;cargo&lt;/code&gt; is Rust’s build tool and package manager.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  🟣 2. Install the Solana CLI
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sh &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;curl &lt;span class="nt"&gt;-sSfL&lt;/span&gt; https://release.solana.com/stable/install&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Confirm it works:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;solana &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Set your network to Devnet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;solana config &lt;span class="nb"&gt;set&lt;/span&gt; &lt;span class="nt"&gt;--url&lt;/span&gt; https://api.devnet.solana.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  🔵 3. Install Anchor (Solana's Rust Framework)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cargo &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--git&lt;/span&gt; https://github.com/coral-xyz/anchor anchor-cli &lt;span class="nt"&gt;--locked&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Anchor abstracts away boilerplate and makes Solana smart contract dev enjoyable.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Test the install:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;anchor &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🧪 Let’s Write Your First Rust App
&lt;/h2&gt;

&lt;p&gt;Run this in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cargo new hello_rust
&lt;span class="nb"&gt;cd &lt;/span&gt;hello_rust
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Edit &lt;code&gt;src/main.rs&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"🚀 Hello, Solana Developer!"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cargo run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;🚀 Hello, Solana Developer!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Boom. You're now a Rustacean! 🦀&lt;/p&gt;




&lt;h2&gt;
  
  
  📖 Assignment (Do This Now)
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Install Rust, Solana CLI, and Anchor&lt;/li&gt;
&lt;li&gt;Create a new Rust CLI project named &lt;code&gt;greeter&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Accept the user's name from terminal input and greet them:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;io&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"What's your name?"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nn"&gt;io&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;stdin&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.read_line&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Failed to read input"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Welcome to Solana, {}!"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="nf"&gt;.trim&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🧠 Practice Exercises
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Get Your Public Key
&lt;/h3&gt;

&lt;p&gt;Run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;solana address
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, print it in your Rust app using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"My Solana address: {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;YOUR_PUBKEY_HERE&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Add a Balance Checker (Mock)
&lt;/h3&gt;

&lt;p&gt;Add a variable &lt;code&gt;let balance = 2.5;&lt;/code&gt; and print if the user is eligible for an airdrop based on their balance.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧨 Bonus: Initialize Your First Anchor Project
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;anchor init mysolanaapp
&lt;span class="nb"&gt;cd &lt;/span&gt;mysolanaapp
anchor build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You’ll see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Program ID: ...
Built &lt;span class="k"&gt;in &lt;/span&gt;target/deploy/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just like that, your first on-chain Solana program is ready to deploy!&lt;/p&gt;




&lt;h2&gt;
  
  
  🎯 What’s Next?
&lt;/h2&gt;

&lt;p&gt;In the next episode EP02 – Rust Ownership &amp;amp; Borrowing Explained, we’ll explore &lt;strong&gt;Rust’s ownership model&lt;/strong&gt;, &lt;strong&gt;borrowing rules&lt;/strong&gt;, and how it leads to &lt;strong&gt;memory safety&lt;/strong&gt; — critical for writing secure blockchain programs.&lt;/p&gt;




&lt;h2&gt;
  
  
  🙌 Let’s Connect
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;💬 Questions? Drop a comment below&lt;/li&gt;
&lt;li&gt;🧠 Want to follow the full course? Bookmark or follow me&lt;/li&gt;
&lt;li&gt;📦 GitHub repo for this series:&lt;a href="https://github.com/SoleerLabs/rust-solana-classes" rel="noopener noreferrer"&gt;Here&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;If you liked this post, consider clapping 👏 and sharing with other Rust-curious blockchain devs!&lt;/p&gt;

</description>
      <category>programming</category>
      <category>rust</category>
      <category>solana</category>
      <category>blockchain</category>
    </item>
    <item>
      <title>Why 'Not Your Keys, Not Your Crypto' Is Failing Web3—and How CeFi Can Fix It</title>
      <dc:creator>Son DotCom 🥑💙</dc:creator>
      <pubDate>Mon, 31 Mar 2025 12:30:07 +0000</pubDate>
      <link>https://dev.to/charles_lukes/why-not-your-keys-not-your-crypto-is-failing-web3-and-how-cefi-can-fix-it-122e</link>
      <guid>https://dev.to/charles_lukes/why-not-your-keys-not-your-crypto-is-failing-web3-and-how-cefi-can-fix-it-122e</guid>
      <description>&lt;p&gt;&lt;em&gt;The Decentralized Dream Is Stalling. Here’s Why Centralized Finance with MPC Could Be the Key to Mass Adoption.&lt;/em&gt;  &lt;/p&gt;

&lt;p&gt;I’ve spent four years in Web3, and I’m calling it: the 'not your keys, not your crypto' mantra is a roadblock. It’s built on assumptions that crumble outside the crypto echo chamber—and if we want a billion users, we need to rethink it.  &lt;/p&gt;

&lt;p&gt;First flaw: It assumes everyone can custody their own keys. Reality check—over 70% of the world isn’t technical. My grandma isn’t securing seed phrases or debugging wallet errors. Most won’t.  &lt;/p&gt;

&lt;p&gt;Second flaw: Self-custody is a UX nightmare. Sign this, approve that, lose your phrase—you’re screwed. Smart contracts? More signatures. It’s not freedom; it’s friction. Adoption’s stuck because we’re building for the 1%, not the 70%.  &lt;/p&gt;

&lt;p&gt;Here’s the fix: Centralized Finance (CeFi)—but not the old kind. Think CeFi 2.0: systems using Multi-Party Computation (MPC) to secure keys &lt;em&gt;for us&lt;/em&gt;. No single point of failure, no seed phrase stress. Your keys are split, encrypted, and managed—CEO can’t touch them, but you’re still in control. Coinbase is already doing this. Devs, take note: this is where the puck’s going.  &lt;/p&gt;

&lt;p&gt;Picture it: businesses auto-signing transactions securely. No pop-ups, no babysitting. Pair it with Google-auth simplicity, and suddenly Web3 isn’t just for nerds. Purists will cry 'centralization!'—but pure decentralization is a fantasy that gatekeeps the masses.  &lt;/p&gt;

&lt;p&gt;The next killer app isn’t another DEX. It’s a secure, scalable CeFi layer that unlocks blockchain for everyone. Devs, stop preaching dogma. Build for the real world. Who’s in?"&lt;/p&gt;

</description>
      <category>web3</category>
      <category>blockchain</category>
      <category>mpc</category>
      <category>cefi</category>
    </item>
    <item>
      <title>Mastering Rust's Ownership: The Key to Memory Safety and Efficiency</title>
      <dc:creator>Son DotCom 🥑💙</dc:creator>
      <pubDate>Mon, 14 Aug 2023 08:29:19 +0000</pubDate>
      <link>https://dev.to/charles_lukes/mastering-rusts-ownership-the-key-to-memory-safety-and-efficiency-124n</link>
      <guid>https://dev.to/charles_lukes/mastering-rusts-ownership-the-key-to-memory-safety-and-efficiency-124n</guid>
      <description>&lt;p&gt;The ownership mechanism in Rust is a unique feature that sets it apart from other mainstream programming languages. It's what makes Rust both memory-safe and efficient while avoiding the need for a garbage collector, a common feature in languages like Java, Go, and Python. Understanding ownership is crucial for becoming proficient in Rust. In this article, we will explore the following topics: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Stack and Heap &lt;/li&gt;
&lt;li&gt;Variable Scope&lt;/li&gt;
&lt;li&gt;Ownership&lt;/li&gt;
&lt;li&gt;Borrowing (Referencing) &lt;/li&gt;
&lt;li&gt;Mutable Reference &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; This article is beginner-friendly. Familiarity with Rust's basic syntax, variable declaration within functions, and basic data types is assumed. If you need a quick refresher, you can check out this &lt;a href="https://dev.to/charles_lukes/introduction-to-common-programming-concepts-in-rust-1c10"&gt;guide&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Stack AND Heap
&lt;/h2&gt;

&lt;p&gt;Memory in Rust can be divided into two main parts: the stack and the heap. Both of these are available during both compile time and runtime and serve different purposes. Understanding their mechanics is crucial for writing efficient Rust code. &lt;/p&gt;

&lt;h3&gt;
  
  
  Stack
&lt;/h3&gt;

&lt;p&gt;The stack is used to store data with known sizes at compile time. The size of data stored on the stack is fixed and cannot be changed during runtime.&lt;/p&gt;

&lt;p&gt;The stack operates using a First In, Last Out (FILO) mechanism, similar to stacking plates. The first plate added is the last one removed.&lt;/p&gt;

&lt;p&gt;Rust automatically adds primitive types to the stack:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;i32&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; 
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;character&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sc"&gt;'a'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;tp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 

    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"number = {}, array = {:?}, character = {}, tp = {:?}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;character&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tp&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The stack layout for the &lt;code&gt;main&lt;/code&gt; method would be as follows:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Address&lt;/th&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;tp&lt;/td&gt;
&lt;td&gt;(1, true)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;character&lt;/td&gt;
&lt;td&gt;'a'&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;array&lt;/td&gt;
&lt;td&gt;[1,2,4]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;num&lt;/td&gt;
&lt;td&gt;14&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;In this table, the &lt;code&gt;num&lt;/code&gt; variable, being the first added, will be the last removed when the function scope ends.&lt;/p&gt;

&lt;p&gt;Note: Address column uses numbers as representation, ideally addresses in computers are not just numbers. &lt;/p&gt;

&lt;h3&gt;
  
  
  Heap
&lt;/h3&gt;

&lt;p&gt;The heap is used for data with sizes unknown at compile time. Types like &lt;code&gt;Vec&lt;/code&gt;, &lt;code&gt;String&lt;/code&gt;, and &lt;code&gt;Box&lt;/code&gt; are stored on the heap automatically.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;i32&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;new_str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The memory mapping for data on the heap is as follows:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;STACK MEM&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Address&lt;/th&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;new_str&lt;/td&gt;
&lt;td&gt;ptr1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;num&lt;/td&gt;
&lt;td&gt;14&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;HEAP MEM&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Address&lt;/th&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;ptr1&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;""&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;When storing data on the heap, a pointer (like &lt;code&gt;ptr1&lt;/code&gt;) is first stored on the stack. This pointer then references the actual data on the heap. This additional step makes heap access slower compared to stack access.&lt;/p&gt;

&lt;p&gt;With stack and heap mechanisms understood, let's delve into variable scope. &lt;/p&gt;

&lt;h3&gt;
  
  
  Variable Scope
&lt;/h3&gt;

&lt;p&gt;Variable scope defines the range in code where a variable is valid. In Rust, curly braces create blocks, and variables within these blocks are scoped to them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;// everything here is scoped to this block&lt;/span&gt;
 &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;hello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Hello World"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Variables within a block cannot be accessed outside that block:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;hello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Hello World"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 

  &lt;span class="c1"&gt;// inner block&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

 &lt;span class="c1"&gt;// This will fail to compile&lt;/span&gt;
 &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{} {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From the above you can't use &lt;code&gt;num&lt;/code&gt; outside the inner block because it is scoped only to the inner block. &lt;/p&gt;

&lt;p&gt;Rust runs functions from top to bottom, allocating stack and heap memory as needed. When the scope ends, Rust calls the &lt;code&gt;drop&lt;/code&gt; method internally to deallocate memory, a crucial concept for understanding Rust's approach to memory management.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ownership
&lt;/h2&gt;

&lt;p&gt;Here we come to the heart of the article, where we explore ownership and its impact on Rust programming. Remember these ownership rules as we proceed:&lt;/p&gt;

&lt;h3&gt;
  
  
  Ownership Rules
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;There can only be one owner of a value at a time. &lt;/li&gt;
&lt;li&gt;Each value has an owner. &lt;/li&gt;
&lt;li&gt;If the owner goes out of scope the value is dropped. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Lets see what this mean below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nd"&gt;vec!&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; 
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;new_array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;new_title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 

    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"array {:?} title {} new_array {:?} new_title {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;new_array&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;new_title&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5spdyhmlz8ghvk3kfa0g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5spdyhmlz8ghvk3kfa0g.png" alt="move bug"&gt;&lt;/a&gt;&lt;br&gt;
The compilation error "borrow of moved value" arises because both &lt;code&gt;array&lt;/code&gt; and &lt;code&gt;title&lt;/code&gt; are being owned by multiple variables simultaneously. This violates the ownership rules.&lt;/p&gt;

&lt;p&gt;Rust's memory layout for the code above is as follows:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;STACK MEM&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Address&lt;/th&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;new_title&lt;/td&gt;
&lt;td&gt;ptr2Copy&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;new_array&lt;/td&gt;
&lt;td&gt;ptr1Copy&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;title&lt;/td&gt;
&lt;td&gt;ptr2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;array&lt;/td&gt;
&lt;td&gt;ptr1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;HEAP MEM&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Address&lt;/th&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;ptr2 and ptr2Copy&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;""&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ptr1 and ptr1Copy&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;vec![1,2,3]&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;As seen from above because vectors and strings are non fixed size types Rust allocates them to the heap and can be accessed via pointer from the stack. &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;ptr1Copy&lt;/code&gt; pointer is a copy of &lt;code&gt;ptr1&lt;/code&gt; pointer and the &lt;code&gt;ptr2Copy&lt;/code&gt; pointer is a copy of &lt;code&gt;ptr2&lt;/code&gt; pointer. &lt;/p&gt;

&lt;p&gt;When Rust is done it then calls the &lt;code&gt;drop&lt;/code&gt; method, the &lt;code&gt;drop&lt;/code&gt; method walks through the stack remember &lt;strong&gt;FILO&lt;/strong&gt; we explained above? It starts by removing the last item added to the stack which is &lt;code&gt;new_title&lt;/code&gt; then finds out it has a pointer(&lt;code&gt;ptr2Copy&lt;/code&gt;) goes to the heap memory via that pointer and removes the string value. It continues to the next element on the stack &lt;code&gt;new_array&lt;/code&gt; which also has a pointer &lt;code&gt;ptr1Copy&lt;/code&gt; and removes the vector from the heap memory too. It again continues to the next which is &lt;code&gt;title&lt;/code&gt; and has a pointer &lt;code&gt;ptr2&lt;/code&gt; but when it follows the pointer it realises that the data no longer exits as it has been removed via &lt;code&gt;ptr2Copy&lt;/code&gt; this why it throws error for &lt;code&gt;title&lt;/code&gt; the same thing goes for the &lt;code&gt;array&lt;/code&gt; variable. &lt;/p&gt;

&lt;p&gt;The Ownership rules apply only to Rust types on the heap. Primitive types on the stack don't follow these rules:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; 
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"hello"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;new_array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;new_title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 

    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"array {:?} title {} new_array {:?} new_title {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;new_array&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;new_title&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi2zjs2u76y3g1w4pva5h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi2zjs2u76y3g1w4pva5h.png" alt="primitive copy types"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For readers familiar with other languages, reassigning values to new variables while they're on the heap might seem intuitive. How do we achieve this in Rust?&lt;/p&gt;

&lt;p&gt;We can use the &lt;code&gt;.clone&lt;/code&gt; method, which duplicates the heap value and stores it in a new location on the heap:&lt;/p&gt;

&lt;p&gt;See below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nd"&gt;vec!&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; 
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;new_array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="nf"&gt;.clone&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;new_title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="nf"&gt;.clone&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 

    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"array {:?} num {} new_array {:?} new_num {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;new_array&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;new_title&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From the above the code works now, let's see how the translation is done on the stack and heap&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;STACK MEM&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Address&lt;/th&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;new_title&lt;/td&gt;
&lt;td&gt;ptr2Copy&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;new_array&lt;/td&gt;
&lt;td&gt;ptr1Copy&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;title&lt;/td&gt;
&lt;td&gt;ptr2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;array&lt;/td&gt;
&lt;td&gt;ptr1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;HEAP MEM&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Address&lt;/th&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;ptr2Copy&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;""&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ptr1Copy&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;vec![1,2,3]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ptr2&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;""&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ptr1&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;vec![1,2,3]&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;While this approach works, it might result in unnecessary memory consumption and inefficiencies. &lt;/p&gt;

&lt;h2&gt;
  
  
  Borrowing
&lt;/h2&gt;

&lt;p&gt;In Rust, borrowing (or referencing) allows us to use values without taking ownership. To reference a value, we use the &lt;code&gt;&amp;amp;&lt;/code&gt; sign.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;hello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"hello"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;another_hello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nd"&gt;vec!&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;another_arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"hello = {} another_hello = {} {:?} {:?}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;another_hello&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;another_arr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By referencing values, we can read data without copying it, avoiding unnecessary memory overhead.&lt;/p&gt;

&lt;p&gt;This is also applicable for functions parameters. Function parameters have their own scope, passing a value to it will automatically move the ownership to the parameters.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"John"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;say_hello&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;say_hello&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"hello {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fafamvmau0387niloze2w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fafamvmau0387niloze2w.png" alt="ownership in function params"&gt;&lt;/a&gt;&lt;br&gt;
The above failed because the ownership of value "John" was moved to the function params. &lt;/p&gt;

&lt;p&gt;We can resolve this error by borrowing from the name owner, see below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"John"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;say_hello&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;say_hello&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"hello {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We don't have anymore errors, looks good so far. &lt;/p&gt;

&lt;p&gt;All these while we've only read the value from the owner what if we want to update that value and still not take ownership? &lt;/p&gt;

&lt;h2&gt;
  
  
  Mutable References
&lt;/h2&gt;

&lt;p&gt;Mutating values in Rust requires the &lt;code&gt;mut&lt;/code&gt; keyword, and to mutate a value via reference, we use the &lt;code&gt;&amp;amp;mut&lt;/code&gt; keyword.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"John"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nf"&gt;full_name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Your full name is: {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;full_name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="nf"&gt;.push_str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;" Doe"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From above the &lt;code&gt;full_name&lt;/code&gt; function is able to update the name value without taking ownership of the value. &lt;/p&gt;

&lt;p&gt;One thing to always remember is at any given time, you can have either one mutable reference or any number of immutable references.&lt;br&gt;
So the following code will fail to compile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"hello"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;r1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;r2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{}, {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7a49wzr6jeg34d5oxl8s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7a49wzr6jeg34d5oxl8s.png" alt="multiple mutable reference fail"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Even if we are just reading the value &lt;code&gt;hello&lt;/code&gt; as far as we have a single mutable reference rust complains. The below still fails to compile&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"hello"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;r1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;r2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;r3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{}, {}, {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The reason for this is to avoid data inconsistencies because rust cannot guarantee at what point the reading or data change will happen. &lt;/p&gt;

&lt;p&gt;We can make the above work with scope.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"hello"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// inner scope &lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;r1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
     &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;r2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also we can read all read references and be done with them before mutating.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"hello"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;r1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// no problem&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;r2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// no problem&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{} and {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// variables r1 and r2 will not be used after this point&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;r3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// no problem&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Rust enforces us to think of our code properly to avoid writing buggy code that are hard to fix. &lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In the world of programming languages, Rust stands out as a remarkable choice due to its ownership mechanism. This mechanism, while initially challenging to grasp, is the cornerstone of Rust's memory safety and efficiency. By strictly adhering to rules that enforce single ownership, Rust mitigates the risk of memory leaks, data inconsistencies, and other common programming pitfalls.&lt;/p&gt;

&lt;p&gt;Through this article, we've explored the intricate workings of Rust's ownership concept. We began with a foundational understanding of the stack and heap, the pillars that support memory allocation. The stack, efficient for fixed-size data, and the heap, accommodating dynamic data, together enable Rust to balance performance and flexibility.&lt;/p&gt;

&lt;p&gt;The significance of variable scope became evident as we delved into the importance of block-level scoping. Rust's rigorous scope management not only simplifies code but also assists in automating memory deallocation through the drop mechanism.&lt;/p&gt;

&lt;p&gt;Ownership, the core of Rust's memory management philosophy, teaches us the invaluable lesson that only one entity can own a value at any given time. This principle may initially seem restrictive, but it's an essential safeguard against data races and memory issues.&lt;/p&gt;

&lt;p&gt;We learned how to navigate these ownership rules by utilizing borrowing, a mechanism that allows controlled access to values without compromising ownership. We saw how references (&lt;code&gt;&amp;amp;&lt;/code&gt;) and mutable references (&lt;code&gt;&amp;amp;mut&lt;/code&gt;) facilitate this process, enabling both reading and manipulation without sacrificing data integrity.&lt;/p&gt;

&lt;p&gt;In a landscape where memory safety is often sacrificed for convenience, Rust shines as a language that compels developers to adopt best practices. While the ownership model can be challenging, mastering it will make you a more disciplined and effective Rust programmer.&lt;/p&gt;

&lt;p&gt;As you continue your journey with Rust, remember that ownership isn't just a technicality; it's a mindset. Embrace it, let it guide your coding decisions, and you'll unlock the true potential of this language. Rust's ownership is not merely a hurdle to overcome; it's a superpower to wield responsibly.&lt;/p&gt;

&lt;p&gt;So, as you write your Rust code, keep these ownership principles in mind, and you'll be well on your way to creating robust, efficient, and reliable software that stands the test of time.&lt;/p&gt;

</description>
      <category>rust</category>
      <category>programming</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Introduction to Common Programming Concepts in Rust</title>
      <dc:creator>Son DotCom 🥑💙</dc:creator>
      <pubDate>Fri, 21 Jul 2023 04:52:47 +0000</pubDate>
      <link>https://dev.to/charles_lukes/introduction-to-common-programming-concepts-in-rust-1c10</link>
      <guid>https://dev.to/charles_lukes/introduction-to-common-programming-concepts-in-rust-1c10</guid>
      <description>&lt;p&gt;In this article, we'll explore some fundamental programming concepts present in Rust, such as variables, conditions, and basic types. To make the most out of this article, it's recommended to have some prior experience with at least one programming language like Python, JavaScript, or Java.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Rust
&lt;/h2&gt;

&lt;p&gt;Rust is a statically typed programming language designed for performance and safety. Originally developed at Mozilla, it caters to system-level programmers who work with low-level byte tweaking code. You can learn more about the history of Rust &lt;a href="https://en.wikipedia.org/wiki/Rust_(programming_language)" rel="noopener noreferrer"&gt;here&lt;/a&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;As this article primarily focuses on teaching programming concepts, we won't delve deep into installation. If you wish to install Rust globally on your computer, you can follow the instructions &lt;a href="https://www.rust-lang.org/tools/install" rel="noopener noreferrer"&gt;here&lt;/a&gt;. Alternatively, you can code along with the article using the &lt;a href="https://play.rust-lang.org/" rel="noopener noreferrer"&gt;Rust Playground app&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let's dive right in and start exploring Rust!&lt;/p&gt;

&lt;h3&gt;
  
  
  Variables
&lt;/h3&gt;

&lt;p&gt;Declaring variables in Rust is straightforward. We use the &lt;code&gt;let&lt;/code&gt; keyword to do so.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;   &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;even_number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is similar to the &lt;code&gt;let&lt;/code&gt; keyword in JavaScript, but Rust treats it differently. By default, variables in Rust are immutable, meaning you can't change the value assigned to a variable.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F56kdwg5c9nyue2pnf3iy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F56kdwg5c9nyue2pnf3iy.png" alt="code representing rust variable declaration without mut keyword"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As shown above, our code fails because we are unable to change the value of our variable &lt;code&gt;even_number&lt;/code&gt;. To change the value of a variable, we must add the &lt;code&gt;mut&lt;/code&gt; keyword, which stands for "mutate."&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt; &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;even_number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjygxun39hhpsfnttynd1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjygxun39hhpsfnttynd1.png" alt="code representing rust variable declaration with mut keyword"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, our code runs fine and prints an output (Note: ignore the warning signs for now, they only indicate that we haven't used the &lt;code&gt;even_number&lt;/code&gt; variable).&lt;/p&gt;

&lt;p&gt;A variable in Rust can only have one type, which can either be explicitly assigned or inferred by the Rust compiler. Unlike JavaScript, once a type is assigned to a variable in Rust, it cannot be changed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt; &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;even_number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// This will not compile&lt;/span&gt;
 &lt;span class="n"&gt;even_number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7uqphx3dn6rwvv5ve7bg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7uqphx3dn6rwvv5ve7bg.png" alt="image showing we can change variable types in rust"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As seen above, the Rust compiler throws an error for "mismatched types." It expects the &lt;code&gt;even_number&lt;/code&gt; variable to always be an integer but got a boolean type.&lt;/p&gt;

&lt;h2&gt;
  
  
  Basic Types
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Boolean
&lt;/h3&gt;

&lt;p&gt;A Boolean type is a type that can have only two values: true or false. To declare a boolean in Rust, we use the &lt;code&gt;bool&lt;/code&gt; keyword.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;is_valid&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By default, variables declared as bool are automatically set to false.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;is_updated&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// will be false &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Boolean types are mainly used in conditionals, such as if and else statements, where you can check if a variable is true and proceed accordingly. &lt;/p&gt;

&lt;h3&gt;
  
  
  Integers
&lt;/h3&gt;

&lt;p&gt;Integers in Rust are numbers without decimal points. There are two types of integers in Rust: &lt;code&gt;signed&lt;/code&gt; and &lt;code&gt;unsigned&lt;/code&gt; integers.&lt;/p&gt;

&lt;h4&gt;
  
  
  Signed Integers
&lt;/h4&gt;

&lt;p&gt;Signed integers can be positive or negative. Examples include: 20, -20, 34, -34, etc. Signed integers are represented by adding an &lt;code&gt;i&lt;/code&gt; at the start of the integer range.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;  &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;i64&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1501&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Unsigned Integers
&lt;/h4&gt;

&lt;p&gt;Unsigned integers are only positive integers. Examples include: 20, 34, 42, 382728289, etc. Unsigned integers are represented by adding a &lt;code&gt;u&lt;/code&gt; at the start of the integer range.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;  &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u8&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;54&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The integer type specifies the length of data that the variable can hold. &lt;/p&gt;

&lt;h4&gt;
  
  
  For Signed:
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Length&lt;/th&gt;
&lt;th&gt;Signed&lt;/th&gt;
&lt;th&gt;Range&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;8-bit&lt;/td&gt;
&lt;td&gt;i8&lt;/td&gt;
&lt;td&gt;-128 to 127&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;16-bit&lt;/td&gt;
&lt;td&gt;i16&lt;/td&gt;
&lt;td&gt;-32,768 to 32,767&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;32-bit&lt;/td&gt;
&lt;td&gt;i32&lt;/td&gt;
&lt;td&gt;-2.147e9 to 2.147e9&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;64-bit&lt;/td&gt;
&lt;td&gt;i64&lt;/td&gt;
&lt;td&gt;-9.223e18 to 9.223e18&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;128-bit&lt;/td&gt;
&lt;td&gt;i28&lt;/td&gt;
&lt;td&gt;-1.701e38 to 1.701e38&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h4&gt;
  
  
  For Unsigned:
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Length&lt;/th&gt;
&lt;th&gt;UnSigned&lt;/th&gt;
&lt;th&gt;Range&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;8-bit&lt;/td&gt;
&lt;td&gt;u8&lt;/td&gt;
&lt;td&gt;0 to 255&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;16-bit&lt;/td&gt;
&lt;td&gt;u16&lt;/td&gt;
&lt;td&gt;0 to 65,535&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;32-bit&lt;/td&gt;
&lt;td&gt;u32&lt;/td&gt;
&lt;td&gt;0 to 4.295e9&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;64-bit&lt;/td&gt;
&lt;td&gt;u64&lt;/td&gt;
&lt;td&gt;0 to 1.844e19&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;128-bit&lt;/td&gt;
&lt;td&gt;u28&lt;/td&gt;
&lt;td&gt;0 to 3.403e38&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;If we use an integer type and assign a value below or above the range of that type, Rust will panic.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;   &lt;span class="c1"&gt;// this will not compile &lt;/span&gt;
   &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;i8&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;128&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Floats
&lt;/h3&gt;

&lt;p&gt;Floats are numbers with decimal points. All float types in Rust are signed. There are two types of floats in Rust: &lt;code&gt;f32&lt;/code&gt; and &lt;code&gt;f64&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;   &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;f32&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;20.50&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Character
&lt;/h3&gt;

&lt;p&gt;This type is similar to character in other programming languages and is represented with the char keyword.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;  &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;alphabet&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;char&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sc"&gt;'a'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that the value of the &lt;code&gt;char&lt;/code&gt; type must be enclosed in single quotes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Compound Types
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Arrays
&lt;/h3&gt;

&lt;p&gt;Arrays are used to group data of the same type together. Unlike arrays in JavaScript, Rust arrays are not dynamic. Rust arrays are stored on the stack, so their size and length must be known during initialization.&lt;/p&gt;

&lt;p&gt;To declare an array, use the syntax &lt;code&gt;[type; size]&lt;/code&gt;, where &lt;code&gt;type&lt;/code&gt; is the type of data to store, and &lt;code&gt;size&lt;/code&gt; is the number of elements in the array.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;   &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;students_age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;u8&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Values in an array must be of the same type. You can't have a &lt;code&gt;char&lt;/code&gt; inside an array of numbers like you could in JavaScript.&lt;/p&gt;

&lt;p&gt;Example: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu7emxf1tzg9htd445pc0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu7emxf1tzg9htd445pc0.png" alt="example code showing you can't add multiple types to a single array in Rust"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The above example fails because the &lt;code&gt;char&lt;/code&gt; type was included in the list. &lt;br&gt;
Notice that we didn't explicitly add the array type because Rust can infer it from the provided data.&lt;/p&gt;
&lt;h4&gt;
  
  
  Accessing and Updating Arrays
&lt;/h4&gt;

&lt;p&gt;Accessing an array element in Rust is similar to other programming languages: we use the element's index. &lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; 
   &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt; &lt;span class="c1"&gt;// 3&lt;/span&gt;
   &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt; &lt;span class="c1"&gt;// 7&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To update or mutate an array, we must use the &lt;code&gt;mut&lt;/code&gt; keyword.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; 
   &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
   &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{:?}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// [1,2,3,5,7,8,9]; &lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As shown from the above the first number in the array was changed from 3 to 1. &lt;br&gt;
&lt;strong&gt;NB&lt;/strong&gt;: The &lt;code&gt;:?&lt;/code&gt; is a debug trait, you shouldn't worry about that now but you will need to include that to display the array of numbers. &lt;/p&gt;
&lt;h3&gt;
  
  
  Vectors
&lt;/h3&gt;

&lt;p&gt;Vectors are similar to arrays but are dynamic, meaning their sizes can change. They are stored on the heap rather than the stack. To represent a vector type, use &lt;code&gt;Vec&amp;lt;T&amp;gt;&lt;/code&gt; and initialize it with &lt;code&gt;vec![...]&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;   &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Vec&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;i8&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nd"&gt;vec!&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From the above we declare a vector of type &lt;code&gt;i8&lt;/code&gt; with three values. &lt;/p&gt;

&lt;p&gt;We can also declare a vector with zero initial values using: &lt;code&gt;Vec::new()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;   &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;current_counts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Vec&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;i8&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;Vec&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
   &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{:?}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;current_counts&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// []&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To add more values to a vector, use the &lt;code&gt;.push&lt;/code&gt; method. &lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;  &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;current_counts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Vec&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;i8&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;Vec&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
   &lt;span class="n"&gt;current_counts&lt;/span&gt;&lt;span class="nf"&gt;.push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{:?}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;current_counts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// [5]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To remove items from the vector, use the &lt;code&gt;.pop&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;   &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Vec&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;i8&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nd"&gt;vec!&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; 
   &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="nf"&gt;.pop&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 
   &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="nf"&gt;.pop&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 
   &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{:?}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// [4]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From the above we call the pop method twice which removed two elements from the vector. &lt;/p&gt;

&lt;p&gt;Also just link arrays we also use the index of elements to access those elements in the vector. &lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;   &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Vec&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;i8&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nd"&gt;vec!&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; 
   &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// -5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conditions
&lt;/h2&gt;

&lt;p&gt;Rust conditionals work similarly to other programming languages. To conditionally run a block of code, use the &lt;code&gt;if else&lt;/code&gt; expression. &lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Count is greater than 2"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Count is less than 2"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The conditions must always evaluate to a bool type. The code below will not compile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;   &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="c1"&gt;// This will fail &lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Count is greater than 2"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Count is less than 2"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;count&lt;/code&gt; is an integer type, not a &lt;code&gt;bool&lt;/code&gt; type. Unlike JavaScript, Rust does not implicitly typecast. &lt;/p&gt;

&lt;h2&gt;
  
  
  Loops
&lt;/h2&gt;

&lt;p&gt;Rust offers three kinds of loops: &lt;code&gt;for&lt;/code&gt;, &lt;code&gt;while&lt;/code&gt;, and &lt;code&gt;loop&lt;/code&gt;. &lt;/p&gt;

&lt;h3&gt;
  
  
  For loop
&lt;/h3&gt;

&lt;p&gt;The for loop in Rust is similar to &lt;code&gt;for-in&lt;/code&gt; loops in JavaScript. It is used primarily with arrays and allows you to loop over each element. &lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; 

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"the number is: {num}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also loop over a range with the Rust for loop.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"the number is: {num}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  While loop
&lt;/h3&gt;

&lt;p&gt;While loops execute a block of code repeatedly as long as a condition is &lt;code&gt;true&lt;/code&gt;. The loop breaks when the condition becomes &lt;code&gt;false&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; 
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;cal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;cal&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"the current calculated value is: {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cal&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;cal&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From the above the loop will continue to until the variable &lt;code&gt;cal&lt;/code&gt; is greater than 20 then it stops. &lt;/p&gt;

&lt;h3&gt;
  
  
  loop
&lt;/h3&gt;

&lt;p&gt;The loop executes a block of code infinitely until you manually stop it using the &lt;code&gt;break&lt;/code&gt; keyword.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;loop&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"The counter is currently {counter}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
           &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Total counter is {counter}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Function
&lt;/h2&gt;

&lt;p&gt;Declaring a function in Rust is similar to other programming languages. So far, we have seen the &lt;code&gt;main&lt;/code&gt; function, which serves as the entry point that Rust looks for when running our code.&lt;/p&gt;

&lt;p&gt;We can create our own functions with different names and use them in the &lt;code&gt;main&lt;/code&gt; function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;addition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"result: {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

 &lt;span class="p"&gt;}&lt;/span&gt;

 &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;addition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;i8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;num2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;i8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;i8&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;num1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;num2&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, we created a function named &lt;code&gt;addition&lt;/code&gt; with two arguments, &lt;code&gt;num1&lt;/code&gt; and &lt;code&gt;num2&lt;/code&gt;, both of type &lt;code&gt;i8&lt;/code&gt;, and a return type &lt;code&gt;-&amp;gt; i8&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Notice that within the &lt;code&gt;addition&lt;/code&gt; function, we didn't explicitly add the &lt;code&gt;return&lt;/code&gt; keyword. This is valid because Rust will implicitly return any line within the function that doesn't end with a semicolon &lt;/p&gt;

&lt;h2&gt;
  
  
  Exercise
&lt;/h2&gt;

&lt;p&gt;Now that we've covered a lot of ground, it's time to test your skills with an exercise:&lt;/p&gt;

&lt;p&gt;Write a program that uses println! to print all the numbers from 1 to 100, with two exceptions. For numbers divisible by 3, print "Fizz" instead of the number, and for numbers divisible by 5 (but not 3), print "Buzz" instead. For numbers divisible by both 3 and 5, print "FizzBuzz".&lt;/p&gt;

&lt;p&gt;In conclusion, this article provided an introductory overview of common programming concepts in Rust. We explored variables, conditions, basic types, and compound types like arrays and vectors. Additionally, we covered loops, functions, and even challenged ourselves with an exercise to solidify our understanding. Rust's focus on performance and safety makes it an excellent choice for system-level programming and low-level optimizations. As you continue your journey with Rust, remember that practice is key to mastering any programming language. Embrace the power of Rust's expressive syntax and its robust features to build efficient and secure applications. Happy coding!&lt;/p&gt;

</description>
      <category>rust</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>A beginner's guide to Blockchain</title>
      <dc:creator>Son DotCom 🥑💙</dc:creator>
      <pubDate>Tue, 06 Apr 2021 09:33:12 +0000</pubDate>
      <link>https://dev.to/charles_lukes/a-beginer-guide-to-blockchain-4bhl</link>
      <guid>https://dev.to/charles_lukes/a-beginer-guide-to-blockchain-4bhl</guid>
      <description>&lt;h2&gt;
  
  
  Concept of Blockchain
&lt;/h2&gt;

&lt;p&gt;Imagine an open platform in which anyone can join similar to whatsapp groups, before any message is delievered on this platform it most go through validation (certain rules set by the group), this validation is done by some selected platform members known as validators. &lt;br&gt;
    Also anyone who joins in will have a copy of all previous messages sent to the platform, say the platform was created on the 3rd of January and you joined on the 10th of Febuary, you will get a copy of all messages sent to the group since it creation. &lt;br&gt;
    Lastly every new message successfully delievered will come along with previous messages and everyone has their own copy. &lt;/p&gt;

&lt;p&gt;That is it, in a simple level this is what blockchain is, the message delievered on the platform represents a &lt;strong&gt;block&lt;/strong&gt; (which is a record of data), and the messages are delievered along with previous messages and that creates a chain of messages hence &lt;strong&gt;blockchain&lt;/strong&gt; (records of data that are chain together by a cryptographic algorithm).&lt;br&gt;&lt;br&gt;
The validators are responsible for verifying that a block is valid within the blockchain, so they check that the block is not malicious and that it conforms to the rules of the system.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Blockchain
&lt;/h2&gt;

&lt;p&gt;The blockchain is a timestamped series of immutable records of data managed by tons of computers and not controlled by a single entity ( eg: Google, Amazon, Reddit etc ). &lt;/p&gt;

&lt;p&gt;An example of what a block looks like&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7y1ntzm9dhk72roh2dem.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7y1ntzm9dhk72roh2dem.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;source&lt;/em&gt;: &lt;a href="https://etherscan.io/" rel="noopener noreferrer"&gt;https://etherscan.io/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From the above this looks like a ledger where activities of this block is recorded. &lt;/p&gt;

&lt;p&gt;Okay Charles why is this really important? &lt;/p&gt;

&lt;h2&gt;
  
  
  Why Blockchain
&lt;/h2&gt;

&lt;p&gt;The nature of blockchain brings a lot of ground breaking benefits, in fact it is the game changer! some of these benefits includes. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Decentralization&lt;/li&gt;
&lt;li&gt;Immutability&lt;/li&gt;
&lt;li&gt;Transparency&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Decentralization
&lt;/h4&gt;

&lt;p&gt;Most applications makes use of a centralized system, an example of such are your bank apps. The problem with this system is, if for whatever reason the system is down, the users wont be able to use the app. Also if for whatever reason the system crashes the users looses all their money (terrible!).&lt;br&gt;
Blockchain is a decentralized system in that records are stored in various nodes (computers) participating in the network.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe9ksz28u3nudq04tc1pg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe9ksz28u3nudq04tc1pg.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;source&lt;/em&gt;: &lt;a href="https://101blockchains.com/decentralized-vs-centralized/" rel="noopener noreferrer"&gt;https://101blockchains.com/decentralized-vs-centralized/&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Immutability
&lt;/h4&gt;

&lt;p&gt;Informations such as your account balance and transactions are stored in a central database. Lets say you have $5000 in you bank account, if an attacker have access to the central database, the attacker can easily update your $5000 to $500 and that becomes your new balance. &lt;br&gt;
Due to the nature of blockchain which nodes in the network has copy of all records on the blockchain if an attacker decides to update a users account balance in a specific node he/she will also need to update that users account balance in all other nodes which is not possible.&lt;/p&gt;

&lt;h4&gt;
  
  
  Transparency
&lt;/h4&gt;

&lt;p&gt;This is one of the most misunderstood concept of blockchain, alot of folks think blockchain is like a &lt;strong&gt;"black market"&lt;/strong&gt; where users activities are hidden. Well that is not true. &lt;br&gt;
This misconception comes from the fact that on the blockchain network a user is not know by their fullname, username or email but by their address. &lt;br&gt;
An example of such address is &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F41i6osca24cwh26x4foz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F41i6osca24cwh26x4foz.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
The blockchain is transparent to everyone on the network and whatever transaction an address does is known by everyone (Remember every node has a copy!).      &lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Blockchain is an open ledger which all transactions done on the network is open to everyone, It is not owned by one person so no one person can bring it down, It is immune to attackers. &lt;/p&gt;

&lt;p&gt;Blockchain is still relatively new and there are still much to learn. I hope this article helps you have at least a little understanding of what blockchain is.     For a more in-depth study I will recommend &lt;a href="https://blockgeeks.com/guides/what-is-blockchain-technology/#Is_Blockchain_Technology_the_New_Internet" rel="noopener noreferrer"&gt;https://blockgeeks.com/guides/what-is-blockchain-technology/#Is_Blockchain_Technology_the_New_Internet&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NB:&lt;/strong&gt; Yes blockchain is not &lt;strong&gt;Bitcoin&lt;/strong&gt;, Bitcoin use the blockchain technology for its processes, and because Bitcoin was the first to successfully used this technology people use both words interchangeably. &lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>javascript</category>
      <category>dapps</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
