mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-25 12:04:21 +01:00
If you have a `&str` you would need to allocate and copy the string just
to pass a reference to it again. Same goes if you have a slice of bytes.
In all (most?) situations, that is not what you want and sometimes
impossible to satisfy. Example:
```rs
impl From<&str> for Value<'_> {
fn from(value: &str) -> Self {
Self::Text(&value.to_owned())
}
}
```
Here, there is no way to pass a reference to a `String` without making
the lifetime `'static`, since the string has to be dropped by the end of
the function or leaked. I would consider this a anti-pattern. There is
no reason to keep a shared reference to a owned value. (And can't think
of any situation where you would need such thing)
Now, this is possible:
```rs
impl<'a> From<&'a str> for Value<'a> {
fn from(value: &'a str) -> Self {
Self::Text(value)
}
}
```
Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>
Closes #838