I see, it is a bit confusing with the edits.
The first problem I had, was the activation of the From<_> trait in Vec, which your macro solved. Thanks again
The second problem I still have is the double code.
Right now it works with the code like this:
#[derive(RustcDecodable, Debug, PartialEq, Clone)]
pub struct KeyboardButton {
pub text: String,
pub request_contact: Option<bool>,
pub request_location: Option<bool>,
}
impl Default for KeyboardButton {
fn default() -> Self {
KeyboardButton {
text: "".into(),
request_contact: None,
request_location: None,
}
}
}
impl From<&'static str> for KeyboardButton {
fn from(text: &'static str) -> Self {
KeyboardButton::new(text, None, None)
}
}
impl From<String> for KeyboardButton {
fn from(text: String) -> Self {
KeyboardButton::new(text, None, None)
}
}
impl KeyboardButton {
pub fn new<S>(text : S, request_contact: Option<bool>, request_location: Option<bool
>) -> Self where S: Into<String> {
KeyboardButton {
text: text.into(),
request_contact: request_contact,
request_location: request_location,
}
}
}
now I would like to reduce the two From<_> implementations to one. Maybe something like this:
impl From<Into<String>> for KeyboardButton {
fn from(text: Into<String>) -> Self {
KeyboardButton::new(text, None, None)
}
}
but I get a compiler error:
/types/mod.rs:711:6: 711:24 error: the trait `core::marker::Sized` is not implemented for the type `core::convert::Into<collections::string::String> + 'static` [E0277]
src/types/mod.rs:711 impl From<Into<String>> for KeyboardButton {
^~~~~~~~~~~~~~~~~~
src/types/mod.rs:711:6: 711:24 help: run `rustc --explain E0277` to see a detailed explanation
src/types/mod.rs:711:6: 711:24 note: `core::convert::Into<collections::string::String> + 'static` does not have a constant size known at compile-time
src/types/mod.rs:711:6: 711:24 note: required by `core::convert::From`
src/types/mod.rs:711:6: 711:24 error: the trait `core::convert::Into` cannot be made into an object [E0038]
src/types/mod.rs:711 impl From<Into<String>> for KeyboardButton {
^~~~~~~~~~~~~~~~~~
src/types/mod.rs:711:6: 711:24 help: run `rustc --explain E0038` to see a detailed explanation
src/types/mod.rs:711:6: 711:24 note: the trait cannot require that `Self : Sized`
src/types/mod.rs:711:6: 711:24 error: the trait `core::marker::Sized` is not implemented for the type `core::convert::Into<collections::string::String> + 'static` [E0277]
src/types/mod.rs:711 impl From<Into<String>> for KeyboardButton {
^~~~~~~~~~~~~~~~~~
src/types/mod.rs:711:6: 711:24 help: run `rustc --explain E0277` to see a detailed explanation
src/types/mod.rs:711:6: 711:24 note: `core::convert::Into<collections::string::String> + 'static` does not have a constant size known at compile-time
src/types/mod.rs:711:6: 711:24 note: required by `core::convert::From`
src/types/mod.rs:711:6: 711:24 error: the trait `core::convert::Into` cannot be made into an object [E0038]
src/types/mod.rs:711 impl From<Into<String>> for KeyboardButton {
^~~~~~~~~~~~~~~~~~
src/types/mod.rs:711:6: 711:24 help: run `rustc --explain E0038` to see a detailed explanation
src/types/mod.rs:711:6: 711:24 note: the trait cannot require that `Self : Sized`
error: aborting due to 2 previous errors
Build failed, waiting for other jobs to finish...
error: aborting due to 2 previous errors
Could not compile `telegram-bot`.
The current source ist on github.