Is there ever a case you'd want to use &String::new() for something expecting &str?

This page summarizes the projects mentioned and recommended in the original post on

Our great sponsors
  • SonarQube - Static code analysis for 29 languages.
  • Scout APM - Less time debugging, more time building
  • SaaSHub - Software Alternatives and Reviews
  • Clippy

    A bunch of lints to catch common mistakes and improve your Rust code

    In a previous PR to clippy, an suggestion from the maintainers (@flip1995) came up to create a lint detecting passing an owned string to something expecting where "" would be accepted. I want to follow up on this and open an issue (and perhaps a PR) to implement this, but first I want to make sure I'm not missing anything.

  • rust

    Empowering everyone to build reliable and efficient software.

    There are ways to enforce it, for example declaring the variable const or static, or using the nightly feature inline_const: which would allow you to write let s = const { String::new() };, ensuring that everything from inside the const block is evaluated at compile time.

  • SonarQube

    Static code analysis for 29 languages.. Your projects are multi-language. So is SonarQube analysis. Find Bugs, Vulnerabilities, Security Hotspots, and Code Smells so you can release quality code every time. Get started analyzing your projects today for free.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts