![]() |
In Rust, we have a concept of multiple bounds. Multiple bounds are defined under the Traits of Rust programming. Multiple bounds in Rust can be applied with a ‘+’ operator and the types are separated using comma (,) For needing more than one bounds in Rust programs, we need to import use::std::fmt::Debug or use::std::fmt::{Debug,Display} Syntax:
Example 1: Rust
Output: ![]()
Explanation: In this example, we have imported the use::std::fmt::{Debug, Display} as we are both printing the debug as well as the display trait. In the main function, we have declared str,_arr and_vec and assigned them values respectively. To see the value of the defined trait gfg_printing_compare that we had declared and passed the Gfgtrait and a variable x that refers to it, we call the function gfg_printing_trait to see the printed values. Example 2: Rust
Output: ![]()
Explanation: In this example, we have imported use::std::debug as the only trait so that we can debug the code from a programmer’s context. We have declared a function gfg_compare_types and passed two traits GFG trait and Debug trait. In the main function, we have declared the _arr and _vec and passed them to the compare_type trait. This trait prints the array and the vector from the function gfg_compare_types. To see the value of what they are printing, the compare_types function is called passing the reference of _arr and _vec into it. |
Reffered: https://www.geeksforgeeks.org
Rust |
Related |
---|
![]() |
![]() |
![]() |
![]() |
|
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 11 |