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 /r/rust

Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
  • Clippy

    A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/

  • 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: https://github.com/rust-lang/rust/issues/76001 which would allow you to write let s = const { String::new() };, ensuring that everything from inside the const block is evaluated at compile time.

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
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