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>, after: Option<String>,
} }
impl RaSub { impl From<&str> for RaSub {
/// Generate subreddit object fn from(name: &str) -> Self {
pub fn new(name: &str) -> RaSub { Self {
RaSub {
name: String::from(name), name: String::from(name),
posts: Vec::new(), posts: Vec::new(),
after: None, after: None,
} }
} }
} }
impl RaSub {
/// Generate subreddit object
pub fn new(name: &str) -> Self {
Self::from(name)
}
}
/// Reddit api client. /// Reddit api client.
/// Uses a [reqwest::Client](https://docs.rs/reqwest/0.11.2/reqwest/struct.Client.html) internally. /// Uses a [reqwest::Client](https://docs.rs/reqwest/0.11.2/reqwest/struct.Client.html) internally.