Formatting and documentation fixes

This commit is contained in:
Cecylia Bocovich 2023-01-30 17:05:38 -05:00
parent 46d51315b6
commit 1da6e245cc
2 changed files with 11 additions and 11 deletions

View File

@ -8,7 +8,6 @@ use futures_util::StreamExt;
use reqwest::Client; use reqwest::Client;
use std::io::{self, BufRead}; use std::io::{self, BufRead};
use std::sync::mpsc; use std::sync::mpsc;
use tokio;
pub mod proto; pub mod proto;
@ -55,15 +54,15 @@ impl Iterator for ResourceStream {
Some(b'\r') => match serde_json::from_slice(&self.buf) { Some(b'\r') => match serde_json::from_slice(&self.buf) {
Ok(diff) => { Ok(diff) => {
self.buf.clear(); self.buf.clear();
return Ok(Some(diff)); Ok(Some(diff))
} }
Err(e) => return Err(Error::JSON(e)), Err(e) => Err(Error::JSON(e)),
}, },
Some(n) => { Some(n) => {
self.buf.push(n); self.buf.push(n);
return Ok(None); Ok(None)
} }
None => return Ok(None), None => Ok(None),
}, },
Err(e) => Err(Error::Io(e)), Err(e) => Err(Error::Io(e)),
} }
@ -171,9 +170,10 @@ mod tests {
/// if successful /// if successful
/// ///
/// # Examples /// # Examples
///
/// ```ignore
/// use rdsys_backend::start_stream; /// use rdsys_backend::start_stream;
/// ///
/// ```
/// let endpoint = String::from("http://127.0.0.1:7100/resource-stream"); /// let endpoint = String::from("http://127.0.0.1:7100/resource-stream");
/// let name = String::from("https"); /// let name = String::from("https");
/// let token = String::from("HttpsApiTokenPlaceholder"); /// let token = String::from("HttpsApiTokenPlaceholder");
@ -194,7 +194,7 @@ pub async fn start_stream(
let req = proto::ResourceRequest { let req = proto::ResourceRequest {
request_origin: name, request_origin: name,
resource_types: resource_types, resource_types,
}; };
let json = serde_json::to_string(&req)?; let json = serde_json::to_string(&req)?;
@ -222,7 +222,7 @@ pub async fn start_stream(
} }
}); });
Ok(ResourceStream { Ok(ResourceStream {
rx: rx, rx,
buf: vec![], buf: vec![],
partial: None, partial: None,
}) })

View File

@ -10,11 +10,11 @@ pub struct ResourceRequest {
} }
/// Representation of a bridge resource /// Representation of a bridge resource
#[derive(Deserialize, PartialEq, Debug)] #[derive(Deserialize, PartialEq, Eq, Debug)]
pub struct Resource { pub struct Resource {
pub r#type: String, pub r#type: String,
pub blocked_in: HashMap<String, bool>, pub blocked_in: HashMap<String, bool>,
pub protocol: String, pub protocol: String,
pub address: String, pub address: String,
pub port: u16, pub port: u16,
pub fingerprint: String, pub fingerprint: String,
@ -26,7 +26,7 @@ pub struct Resource {
} }
/// A ResourceDiff holds information about new, changed, or pruned resources /// A ResourceDiff holds information about new, changed, or pruned resources
#[derive(Deserialize, PartialEq, Debug)] #[derive(Deserialize, PartialEq, Eq, Debug)]
pub struct ResourceDiff { pub struct ResourceDiff {
pub new: Option<HashMap<String, Vec<Resource>>>, pub new: Option<HashMap<String, Vec<Resource>>>,
pub changed: Option<HashMap<String, Vec<Resource>>>, pub changed: Option<HashMap<String, Vec<Resource>>>,