Rust - Multiple Bounds Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report 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: use std::fmt::Debug; fn multiple_bounds_demo<GFG: Clone + Debug>(a: GFG) { //methods inside the function trait } Example 1: Rust # Printing Two trait values using multiple bounds #![allow(unused_variables)] use std::fmt::{Debug, Display}; fn gfg_printing_compare<Gfgtrait: Debug + Display>(x: &Gfgtrait) { println!("Debug value of Trait: `{:?}`", x); println!("Display value of Trait: `{}`", x); } fn main() { let str = "GeeksforGeeks"; let _arr = [10, 20, 30, 40, 50]; let _vec = vec![10, 20, 30, 40, 50]; gfg_printing_compare(&str); } 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 # Comparing two trait types using Multiple bounds #![ allow(unused_variables)] use std::fmt::Debug; fn gfg_comparing_types<Gfgtrait: Debug, Debugtrait: Debug>(x: &Gfgtrait, y: &Debugtrait) { println!("Value while passing _arr over x : {:?}", x); println!("Value when we pass _vec over y: {:?}", y); } fn main() { let str = "GeeksforGeeks"; let _arr = [10, 30, 50, 70]; let _vec = vec![20,40,60,80]; gfg_comparing_types(&_arr, &_vec); } 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. Comment More infoAdvertise with us Next Article Conditionals in Rust S sayanc170 Follow Improve Article Tags : Technical Scripter Rust Technical Scripter 2022 Rust generics Similar Reads Rust - Bounds In Rust, we have a concept of Bounds. Bounds are used in situations when we are working with generics and are trying to figure out the nature and type of parameters that are required for stipulating the functionality that the type in Rust implements. Syntax: fn gfg <T: GeeksforGeeks>(x: T) { 2 min read Rust - Multiple Error Types In Rust, sometimes we have scenarios where there is more than one error type. In Rust, the way of handling errors is different compared to other Object Oriented / System languages. Rust specifically uses 'Result' for returning something. The Result <T, E> is basically an enum that has - Ok(T) 3 min read Rust lifetime Constructor In Rust, we have a concept of a lifetime constructor that falls under the ownership category. Rust enforces a certain set of rules through its concept of ownership and lifetimes. In this article, we would be learning more about Lifetimes in Rust. In Rust, there are various regions that are present i 3 min read Loops in Rust A loop is a programming structure that repeats a sequence of instructions until a specific condition is satisfied. Similar to other programming languages, Rust also has two types of loops: Indefinite Loop: While loop and LoopDefinite Loops: For loopLet's explore them in detail. While LoopA simple wa 3 min read Conditionals in Rust Conditional Statements are the decision-making statements based on given conditions. Conditional statements are common in programming languages and rust has them and unlike many of them, the boolean condition doesn't need to be surrounded by parentheses but is better to use, and each condition is fo 3 min read Rust - Lifetime Lifetimes in Rust refer to the lifetime of how long a variable would live. Lifetimes are associated with references as references cannot live longer than the object from which it is derived. Lifetimes basically describe the scope that a reference is valid for. Lifetimes come into play when we are de 3 min read Like