2 Comments
User's avatar
thyrotoxicoses's avatar

I think you should better

```

pub fn greet<S: AsRef<str>>(text: S) {

let name = test.as_ref();

println!("Hello, {}!", name);

}

```

Expand full comment
Cuong Le's avatar

Thanks for the suggestion. `AsRef<str>` is great when you want to accept any “string-like” type, especially for public helpers or utilities that aim for flexibility and ergonomics for all callers.

For a simple `greet`, I stick with `&str`: it already works with `&String` and string literals, keeps the signature clear, and avoids generic monomorphization.

Expand full comment