improv(text_input): use Cow<str> for label, helper, and error text

This commit is contained in:
Soso 2025-01-16 06:29:03 +01:00 committed by GitHub
parent b244970a18
commit 90c5c84cce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -195,9 +195,9 @@ pub struct TextInput<'a, Message> {
padding: Padding, padding: Padding,
size: Option<f32>, size: Option<f32>,
helper_size: f32, helper_size: f32,
label: Option<&'a str>, label: Option<Cow<'a, str>>,
helper_text: Option<&'a str>, helper_text: Option<Cow<'a, str>>,
error: Option<&'a str>, error: Option<Cow<'a, str>>,
on_input: Option<Box<dyn Fn(String) -> Message + 'a>>, on_input: Option<Box<dyn Fn(String) -> Message + 'a>>,
on_paste: Option<Box<dyn Fn(String) -> Message + 'a>>, on_paste: Option<Box<dyn Fn(String) -> Message + 'a>>,
on_submit: Option<Message>, on_submit: Option<Message>,
@ -275,14 +275,14 @@ where
} }
/// Sets the text of the [`TextInput`]. /// Sets the text of the [`TextInput`].
pub fn label(mut self, label: &'a str) -> Self { pub fn label(mut self, label: impl Into<Cow<'a, str>>) -> Self {
self.label = Some(label); self.label = Some(label.into());
self self
} }
/// Sets the helper text of the [`TextInput`]. /// Sets the helper text of the [`TextInput`].
pub fn helper_text(mut self, helper_text: &'a str) -> Self { pub fn helper_text(mut self, helper_text: impl Into<Cow<'a, str>>) -> Self {
self.helper_text = Some(helper_text); self.helper_text = Some(helper_text.into());
self self
} }
@ -293,8 +293,8 @@ where
} }
/// Sets the error message of the [`TextInput`]. /// Sets the error message of the [`TextInput`].
pub fn error(mut self, error: &'a str) -> Self { pub fn error(mut self, error: impl Into<Cow<'a, str>>) -> Self {
self.error = Some(error); self.error = Some(error.into());
self self
} }