feat: constructors for Node

This commit is contained in:
əlemi 2024-03-20 07:54:24 +01:00
parent 9f06aa5993
commit 1cede82df6
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -85,6 +85,18 @@ impl<T : super::Base> Node<T> {
} }
impl Node<serde_json::Value>{ impl Node<serde_json::Value>{
pub fn link(uri: &str) -> Self {
Node::Link(Box::new(uri.to_string()))
}
pub fn object(x: serde_json::Value) -> Self {
Node::Object(Box::new(x))
}
pub fn array(x: Vec<impl super::Base>) -> Self {
Node::Array(x.into_iter().map(|x| Node::object(x.underlying_json_object())).collect())
}
pub async fn fetch(&mut self) -> reqwest::Result<()> { pub async fn fetch(&mut self) -> reqwest::Result<()> {
if let Node::Link(link) = self { if let Node::Link(link) = self {
*self = reqwest::Client::new() *self = reqwest::Client::new()