Filter
Exclude
Time range
-
Near
🔰TRAITS IN RUST: THE SECRET TO BUILDING REUSABLE, TYPE-SAFE BLOCKCHAIN COMPONENTS If you are learning Rust for blockchain development, you will quickly encounter a concept called "traits." They appear everywhere, in error handling, in smart contract frameworks, in the core libraries of Solana and NEAR. Understanding traits is not optional, it is the key to writing code that is flexible, reusable, and safe. So what exactly is a trait? A trait in Rust is a way to define shared behavior. It is like a contract that says, "Any type that implements this trait promises to have these specific methods." You define what methods should exist, but you do not write the implementation yet. Different types can then implement that trait in their own way, and any code that works with the trait can work with all those different types automatically. This is incredibly powerful for Web3 development. Imagine you are building a DeFi protocol that needs to work with multiple different tokens. Instead of writing separate code for each token, you define a Token trait that specifies methods like transfer, balance_of, and approve. Then any token contract that implements this trait can be used by your protocol without any changes. You write the logic once, and it works with everything. Traits also enable something called "generics," which let you write functions that work with any type that implements a certain trait. This means you can build components like a staking pool that works with any staking token, or a governance system that works with any voting mechanism, as long as those things implement the required traits. The compiler checks everything at compile time, so you get maximum flexibility with zero runtime cost. The Universal Charger Analogy: Think of traits like the universal charger standard. Different devices, phones, laptops, headphones, all need power, but they have different power requirements. The USB standard is a trait. It defines what power delivery should look like, what shape the connector should be, how communication works. Any device manufacturer can implement the USB standard in their own way, but because they all follow the same trait, you can plug any of them into the same charger. The charger does not need to know the internal details of your phone, it just needs to know that it implements the "USB powered device" trait. In the same way, your blockchain component does not need to know the internal details of every token or contract it interacts with. It just needs to know that they implement the traits it requires. This is how complex DeFi systems are built from reusable pieces that snap together safely and predictably. How have you used traits in your own Rust code? What patterns have you found most useful? #RustLang #Traits #GenericProgramming #Web3Development #Blockchain #DeFi
2
27
4 Sep 2024
CppCon 2024 SESSION ANNOUNCEMENT: Back to Basics: Generic Programming by David Olsen cppcon2024.sched.com/event/1… Register now: cppcon.org/registration/ #cpp #cplusplus #programming #genericprogramming

1
5
709
3 Sep 2024
CppCon 2024 SESSION ANNOUNCEMENT: Back to Basics: Generic Programming by David Olsen cppcon2024.sched.com/event/1… Register now: cppcon.org/registration/ #cpp #cplusplus #programming #genericprogramming

1
2
648
2 Sep 2024
CppCon 2024 SESSION ANNOUNCEMENT: Back to Basics: Generic Programming by David Olsen cppcon2024.sched.com/event/1… Register now: cppcon.org/registration/ #cpp #cplusplus #programming #genericprogramming

2
744
25 Aug 2024
We have just released a new C Now 2024 Conference Video! Reintroduction to Generic Programming for C Engineers - Nick DeMarco - C Now 2024 youtu.be/tt0-7athgrE #Cplusplus #Cpp #Genericprogramming
3
943
11 Jun 2024
C OnSea 2024 SESSION ANNOUNCEMENT: There Is a Method to the Madness of Performance! by @thecppzoo cpponsea.uk/2024/sessions/th…! Register now at cpponsea.uk/tickets/ #genericprogramming #compilerexplorer #programming #coding
2
156
11 Jun 2024
C OnSea 2024 SESSION ANNOUNCEMENT: Reusable Code, Reusable Data Structures by Sebastian Theophil cpponsea.uk/2024/sessions/re… Register now at cpponsea.uk/tickets/ #BestPractices #GenericProgramming #cpp #cplusplus
1
169
CppOnline Session Announcement Empowerment with C 's Generic Programming Paradigm by @thecppzoo cpponline.uk/session/empower… Register today at cpponline.uk/registration #ChatGPT #GenericProgramming #Iterators #Stepanov #cpponline
2
48
29 Dec 2023
We have just released a new CppCon 2023 Video! Expressing Implementation Sameness and Similarity - Polymorphism in Modern C - by @The_Whole_Daisy youtu.be/Fhw43xofyfo #Cpp23 #GenericProgramming #cppcon
1
7
1,433
17 Sep 2023
Templates Made Easy With C 20 - by @thevibesman - C on Sea 2023 youtube.com/watch?v=z8e5cyZJ… #Cpp20 #Genericprogramming #cpponsea

8
722
13 Sep 2023
We have just released a new C on Sea 2023 Video! Templates Made Easy With C 20 - by @thevibesman - C on Sea 2023 youtube.com/watch?v=z8e5cyZJ… #Genericprogramming #Programming #cpponsea

5
372