Use ToString for Text::new instead of Into<String>
This commit is contained in:
parent
ff2519b1d4
commit
a1c5f8839d
5 changed files with 13 additions and 12 deletions
|
|
@ -40,7 +40,7 @@ impl Sandbox for Counter {
|
|||
fn view(&self) -> Element<Message> {
|
||||
column![
|
||||
button("Increment").on_press(Message::IncrementPressed),
|
||||
text(self.value.to_string()).size(50),
|
||||
text(self.value).size(50),
|
||||
button("Decrement").on_press(Message::DecrementPressed)
|
||||
]
|
||||
.padding(20)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use futures::sink::SinkExt;
|
|||
use futures::stream::StreamExt;
|
||||
|
||||
use async_tungstenite::tungstenite;
|
||||
use std::fmt;
|
||||
|
||||
pub fn connect() -> Subscription<Event> {
|
||||
struct Connect;
|
||||
|
|
@ -63,7 +64,7 @@ pub fn connect() -> Subscription<Event> {
|
|||
}
|
||||
|
||||
message = input.select_next_some() => {
|
||||
let result = websocket.send(tungstenite::Message::Text(String::from(message))).await;
|
||||
let result = websocket.send(tungstenite::Message::Text(message.to_string())).await;
|
||||
|
||||
if result.is_ok() {
|
||||
(None, State::Connected(websocket, input))
|
||||
|
|
@ -133,14 +134,14 @@ impl Message {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Message> for String {
|
||||
fn from(message: Message) -> Self {
|
||||
match message {
|
||||
Message::Connected => String::from("Connected successfully!"),
|
||||
impl fmt::Display for Message {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Message::Connected => write!(f, "Connected successfully!"),
|
||||
Message::Disconnected => {
|
||||
String::from("Connection lost... Retrying...")
|
||||
write!(f, "Connection lost... Retrying...")
|
||||
}
|
||||
Message::User(message) => message,
|
||||
Message::User(message) => write!(f, "{}", message),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ where
|
|||
/// Creates a new [`Text`] widget with the provided content.
|
||||
///
|
||||
/// [`Text`]: widget::Text
|
||||
pub fn text<Renderer>(text: impl Into<String>) -> widget::Text<Renderer>
|
||||
pub fn text<Renderer>(text: impl ToString) -> widget::Text<Renderer>
|
||||
where
|
||||
Renderer: crate::text::Renderer,
|
||||
Renderer::Theme: widget::text::StyleSheet,
|
||||
|
|
|
|||
|
|
@ -45,9 +45,9 @@ where
|
|||
Renderer::Theme: StyleSheet,
|
||||
{
|
||||
/// Create a new fragment of [`Text`] with the given contents.
|
||||
pub fn new<T: Into<String>>(label: T) -> Self {
|
||||
pub fn new<T: ToString>(label: T) -> Self {
|
||||
Text {
|
||||
content: label.into(),
|
||||
content: label.to_string(),
|
||||
size: None,
|
||||
font: Default::default(),
|
||||
width: Length::Shrink,
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@
|
|||
//! button("+").on_press(Message::IncrementPressed),
|
||||
//!
|
||||
//! // We show the value of the counter here
|
||||
//! text(self.value.to_string()).size(50),
|
||||
//! text(self.value).size(50),
|
||||
//!
|
||||
//! // The decrement button. We tell it to produce a
|
||||
//! button("-").on_press(Message::DecrementPressed),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue