Add from to RaSub

This commit is contained in:
Uttarayan Mondal
2021-03-27 00:47:16 +05:30
parent adf5fc178d
commit 646f4fa07c
+9 -4
View File
@@ -106,16 +106,21 @@ pub struct RaSub {
after: Option<String>,
}
impl RaSub {
/// Generate subreddit object
pub fn new(name: &str) -> RaSub {
RaSub {
impl From<&str> for RaSub {
fn from(name: &str) -> Self {
Self {
name: String::from(name),
posts: Vec::new(),
after: None,
}
}
}
impl RaSub {
/// Generate subreddit object
pub fn new(name: &str) -> Self {
Self::from(name)
}
}
/// Reddit api client.
/// Uses a [reqwest::Client](https://docs.rs/reqwest/0.11.2/reqwest/struct.Client.html) internally.