Allow owned values alongside borrowed ones
tbot
uses borrowed values everywhere. This helps to avoid unnecessary allocations and is more memory efficient. However, when values have to be allocated, returning tbot
's types from functions becomes troublesome. For example, one can't do something like this:
use tbot::types::parameters::Text;
fn create_message<'a, 'b>(name: &'a str) -> Text<'b> {
let text = format!("Hi, *{}*", name);
Text::markdown(&text)
}
To fix this, tbot
should allow owned values, while still encouraging borrowing. For example, the problem above could be fixed if Text
would be declared as
use std::borrow::Cow;
pub struct Text<'a> {
text: Cow<'a, str>,
..
}
and its methods would take impl Into<Cow<'a, str>>
instead of &'a str
.
Current progress on this issue:
-
UseCow<'a, str>
everywhere (!223 (merged), !260 (merged)); -
Implement theInteriorBorrow
trait to go from&T
toT
without unnecessary cloning (!262 (merged)); -
Implement From<{MarkdownV2,Html}>
forText
(!256 (merged)); -
UseCow
for arrays; -
Merge duplicate types.
Edited by Artem Starikov