Created
April 26, 2024 12:38
-
-
Save ognis1205/ec0dbf4357cf4e73b6f616bb2d3c6fe2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Accepts any type T as its argument which satisfies 'static lifetime trait bounds. | |
fn generic<T: 'static>(v: T) {} | |
// 1. No references. | |
struct NoReferences(String); | |
// 2. Includes a 'static lifetime reference. | |
struct IncludesStaticRef(&'static str); | |
// 3. Inclues a lifetime reference named 'a | |
struct IncludesNamedRef<'a>(&'a str); | |
fn main() { | |
generic(NoReferences("abc".to_string())); // -- (1) | |
generic(IncludesStaticRef("abc")); // --------- (2) | |
generic(IncludesNamedRef("abc")); // ---------- (3) | |
{ | |
let x: String = format!("abc"); | |
generic(IncludesNamedRef(&x)); // --------- (4) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment