Allow `ProtoString` implementations without requiring `From<&str>` for every lifetime
- Lingua principale
- Rust
- Stelle
- 883
- Fork
- 88
- Merge medio
- 3g 19h
- PR unite (30g)
- 42
Descrizione
Could `ProtoString` replace its `for<'a> From<&'a str>` requirement with a dedicated method for copying borrowed text into owned storage?
I maintain `flexstr`. It supports borrowed strings, inline storage, and reference-counted storage. Its existing `From<&str>` implementation borrows, tying the input lifetime to the output lifetime.
`SharedStr` can safely copy temporary text into owned storage, but implementing buffa’s higher-ranked `From<&str>` bound would require changing that existing conversion’s semantics making it always need to own. A new copying `From` implementation would overlap with the borrowing implementation.
### Suggested approach
Keep `From` and add an overridable method to the `ProtoString` trait such as:
```rust
fn copy_from_str(value: &str) -> Self {
Self::from(String::from(value))
}
```
JSON helpers and generated view-to-owned conversions could use this method. Binary decoding already has the appropriate extension point in `from_wire`.
There is a similar precedent in [buffa’s design](https://github.com/anthropics/buffa/blob/main/DESIGN.md#12-pluggable-owned-types--protostring-and-protobytes): `ProtoBytes` deliberately omits `From<&[u8]>` because `bytes::Bytes` only supports that conversion for static slices.
Thoughts?
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.