microsoft / microsoft/rust-guidelines

M-IMPL-ASREF: clarify additional constraints on where to apply this rule

Open
#24 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
200
Forks
25
Avg merge
3m
Merged PRs (30d)
1

Description

Applying this rule broadly can introduce a lot of generics into the code and therefore increase the compile times. Shouldn't this rule clarify that `impl AsRef` is preferrable on public APIs only? I think for internal helpers is perfectly fine to accept `&str` rather than `impl AsRef`.

I have also tried to run AI agent to apply this rule to my codebase and it was overly zealous. For example it tried to replace:

``` rust
pub struct MyObject;
pub fn process(obj: &MyObject) { ... }
```

with:
``` rust
pub struct MyObject;
pub fn process(obj: impl AsRef) { ... }
```

Where this would not even compile as `MyObject` does not implement `AsRef`. I think this should be clarified so if there is no naive conversion from `AsRef`, the rule should not apply.

Contributor guide

Open the contributing guide

Research direction

Locate the M-IMPL-ASREF rule in the repository and read its current wording and examples. Clarify that the rule primarily applies to public APIs and only when a valid AsRef conversion exists; done means the guidance addresses internal helpers and the non-compiling MyObject example.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.