SlideShare a Scribd company logo
Traits: Defining
Shared Behavior
Presented By: Pawan Bisht
Software Consultant
Knoldus Inc.
01 Trait: Introduction
02 Trait Bounds
03 Trait Objects
Our Agenda
Trait: Introduction
Traits are the abstract mechanism for adding functionality to
types or it tells Rust compiler about functionality a type must
provide.
● Trait Definition (Desired Behavior)
● Trait Implementation
● Default Implementation of a Trait
Trait: Introduction
● Traits can be implemented for Existing Types
● Access Methods Declared in the Same Trait
● Perform Static Dispatch
● Perform Dynamic Dispatch
Quick Demo
Trait Bounds
“Trait Bounds are the longer forms of Passing Parameters as a
Function, with the help of this user can put the restriction into his
functionality like only limited functions can able to use it.”
Trait Bounds
// Passing as a parameter
pub fn function_name(item: impl TraitName) {
}
// Trait Bound
pub fn function_name<T: TraitName> (item: T) {
}
Trait Bounds
// Passing as a parameter
pub fn function_name(item1: impl TraitName, item2: impl
TraitName) {
}
// Trait Bound
pub fn function_name<T: TraitName> (item1: T, item2: T) {
}
Quick Demo
Trait Object
Trait objects, like &Foo or Box<Foo>, are normal values that
store a value of any type that implements the given trait, where
the precise type can only be known at runtime.
Trait Objects performs Dynamic Dispatch
Pointers used to define Trait Objects are : Box, Arc, Rc and &
Traditional Objects
Traits: Introduction to Define Shared Behavior
Traits: Introduction to Define Shared Behavior
Quick Demo
References
● https://doc.rust-lang.org/book/ch10-02-traits.html
● https://doc.rust-lang.org/book/ch17-02-trait-objects.html
● https://www.slideshare.net/NellShamrell/rust-traits-and-you-a-
deep-dive
Thank You!
@Knolspeak
/KnoldusSoftware

More Related Content

PPTX
Java 17 features and implementation.pptx
PPTX
Angular Hydration Presentation (FrontEnd)
PPTX
Optimizing Test Execution: Heuristic Algorithm for Self-Healing
PPTX
Self-Healing Test Automation Framework - Healenium
PPTX
Kanban Metrics Presentation (Project Management)
PPTX
Chaos Mesh Introducing Chaos in Kubernetes
PPTX
GraalVM - A Step Ahead of JVM Presentation
PPTX
Nomad by HashiCorp Presentation (DevOps)
Java 17 features and implementation.pptx
Angular Hydration Presentation (FrontEnd)
Optimizing Test Execution: Heuristic Algorithm for Self-Healing
Self-Healing Test Automation Framework - Healenium
Kanban Metrics Presentation (Project Management)
Chaos Mesh Introducing Chaos in Kubernetes
GraalVM - A Step Ahead of JVM Presentation
Nomad by HashiCorp Presentation (DevOps)

More from Knoldus Inc. (20)

PPTX
Nomad by HashiCorp Presentation (DevOps)
PPTX
DAPR - Distributed Application Runtime Presentation
PPTX
Introduction to Azure Virtual WAN Presentation
PPTX
Introduction to Argo Rollouts Presentation
PPTX
Intro to Azure Container App Presentation
PPTX
Insights Unveiled Test Reporting and Observability Excellence
PPTX
Introduction to Splunk Presentation (DevOps)
PPTX
Code Camp - Data Profiling and Quality Analysis Framework
PPTX
AWS: Messaging Services in AWS Presentation
PPTX
Amazon Cognito: A Primer on Authentication and Authorization
PPTX
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
PPTX
Managing State & HTTP Requests In Ionic.
PPTX
Facilitation Skills - When to Use and Why.pptx
PPTX
Performance Testing at Scale Techniques for High-Volume Services
PPTX
Snowflake and its features (Presentation)
PPTX
Terratest - Automation testing of infrastructure
PPTX
Getting Started with Apache Spark (Scala)
PPTX
Secure practices with dot net services.pptx
PPTX
Distributed Cache with dot microservices
PPTX
Introduction to gRPC Presentation (Java)
Nomad by HashiCorp Presentation (DevOps)
DAPR - Distributed Application Runtime Presentation
Introduction to Azure Virtual WAN Presentation
Introduction to Argo Rollouts Presentation
Intro to Azure Container App Presentation
Insights Unveiled Test Reporting and Observability Excellence
Introduction to Splunk Presentation (DevOps)
Code Camp - Data Profiling and Quality Analysis Framework
AWS: Messaging Services in AWS Presentation
Amazon Cognito: A Primer on Authentication and Authorization
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
Managing State & HTTP Requests In Ionic.
Facilitation Skills - When to Use and Why.pptx
Performance Testing at Scale Techniques for High-Volume Services
Snowflake and its features (Presentation)
Terratest - Automation testing of infrastructure
Getting Started with Apache Spark (Scala)
Secure practices with dot net services.pptx
Distributed Cache with dot microservices
Introduction to gRPC Presentation (Java)
Ad

Recently uploaded (20)

PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
1. Introduction to Computer Programming.pptx
PPTX
Spectroscopy.pptx food analysis technology
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PPTX
Machine Learning_overview_presentation.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Tartificialntelligence_presentation.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Approach and Philosophy of On baking technology
Mobile App Security Testing_ A Comprehensive Guide.pdf
Electronic commerce courselecture one. Pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Encapsulation_ Review paper, used for researhc scholars
1. Introduction to Computer Programming.pptx
Spectroscopy.pptx food analysis technology
Network Security Unit 5.pdf for BCA BBA.
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Machine Learning_overview_presentation.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Assigned Numbers - 2025 - Bluetooth® Document
Unlocking AI with Model Context Protocol (MCP)
Reach Out and Touch Someone: Haptics and Empathic Computing
Tartificialntelligence_presentation.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Diabetes mellitus diagnosis method based random forest with bat algorithm
Approach and Philosophy of On baking technology
Ad

Traits: Introduction to Define Shared Behavior