Run cargo fmt
Signed-off-by: Alex Kattathra Johnson <alex.kattathra.johnson@gmail.com>
This commit is contained in:
parent
5f35894619
commit
e35542ddf3
3 changed files with 14 additions and 17 deletions
17
src/main.rs
17
src/main.rs
|
@ -1,8 +1,11 @@
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use nu_plugin::{EvaluatedCall, JsonSerializer, serve_plugin};
|
use nu_plugin::{serve_plugin, EvaluatedCall, JsonSerializer};
|
||||||
use nu_plugin::{EngineInterface, Plugin, PluginCommand};
|
use nu_plugin::{EngineInterface, Plugin, PluginCommand};
|
||||||
use nu_protocol::{ByteStream, ByteStreamType, Category, LabeledError, PipelineData, Signature, SyntaxShape, Type, Value};
|
use nu_protocol::{
|
||||||
|
ByteStream, ByteStreamType, Category, LabeledError, PipelineData, Signature, SyntaxShape, Type,
|
||||||
|
Value,
|
||||||
|
};
|
||||||
|
|
||||||
mod ws;
|
mod ws;
|
||||||
use ws::client::{connect, http_parse_url, request_headers};
|
use ws::client::{connect, http_parse_url, request_headers};
|
||||||
|
@ -15,9 +18,7 @@ impl Plugin for WebSocketPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn commands(&self) -> Vec<Box<dyn PluginCommand<Plugin = Self>>> {
|
fn commands(&self) -> Vec<Box<dyn PluginCommand<Plugin = Self>>> {
|
||||||
vec![
|
vec![Box::new(WebSocket)]
|
||||||
Box::new(WebSocket),
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,11 +81,7 @@ impl PluginCommand for WebSocket {
|
||||||
.expect("Timeout should be set to duration") as u64,
|
.expect("Timeout should be set to duration") as u64,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
if let Some(cr) = connect(
|
if let Some(cr) = connect(requested_url, timeout, request_headers(headers)?) {
|
||||||
requested_url,
|
|
||||||
timeout,
|
|
||||||
request_headers(headers)?,
|
|
||||||
) {
|
|
||||||
let reader = Box::new(cr);
|
let reader = Box::new(cr);
|
||||||
return Ok(PipelineData::ByteStream(
|
return Ok(PipelineData::ByteStream(
|
||||||
ByteStream::read(
|
ByteStream::read(
|
||||||
|
|
|
@ -100,17 +100,17 @@ pub fn connect(
|
||||||
tungstenite::Message::Text(msg) => {
|
tungstenite::Message::Text(msg) => {
|
||||||
if tx.send(msg.as_bytes().to_vec()).is_err() {
|
if tx.send(msg.as_bytes().to_vec()).is_err() {
|
||||||
websocket.close(Some(tungstenite::protocol::CloseFrame{
|
websocket.close(Some(tungstenite::protocol::CloseFrame{
|
||||||
code: tungstenite::protocol::frame::coding::CloseCode::Normal,
|
code: tungstenite::protocol::frame::coding::CloseCode::Normal,
|
||||||
reason: std::borrow::Cow::Borrowed("byte stream closed"),
|
reason: std::borrow::Cow::Borrowed("byte stream closed"),
|
||||||
})).expect("Could not close connection")
|
})).expect("Could not close connection")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tungstenite::Message::Binary(msg) => {
|
tungstenite::Message::Binary(msg) => {
|
||||||
if tx.send(msg).is_err() {
|
if tx.send(msg).is_err() {
|
||||||
websocket.close(Some(tungstenite::protocol::CloseFrame{
|
websocket.close(Some(tungstenite::protocol::CloseFrame{
|
||||||
code: tungstenite::protocol::frame::coding::CloseCode::Normal,
|
code: tungstenite::protocol::frame::coding::CloseCode::Normal,
|
||||||
reason: std::borrow::Cow::Borrowed("byte stream closed"),
|
reason: std::borrow::Cow::Borrowed("byte stream closed"),
|
||||||
})).expect("Could not close connection")
|
})).expect("Could not close connection")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tungstenite::Message::Close(..) => {
|
tungstenite::Message::Close(..) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue