Cleanup
This commit is contained in:
parent
c4b57ae813
commit
5927b7dfe6
|
@ -34,53 +34,53 @@ async fn run() -> Result<(), GolgiError> {
|
|||
}
|
||||
println!("reached end of stream");
|
||||
|
||||
// create a history stream and convert it into a Vec<SsbMessageValue> using try_collect
|
||||
// (if there is any error in the results, it will be raised)
|
||||
let mut history_stream = sbot_client.create_history_stream(author.to_string()).await?;
|
||||
let results : Vec<SsbMessageValue> = history_stream.try_collect().await?;
|
||||
for x in results {
|
||||
println!("x: {:?}", x);
|
||||
}
|
||||
|
||||
// example to create a history stream and use a map to convert stream of SsbMessageValue
|
||||
// into a stream of KeyTypeTuple (local struct for storing message_key and message_type)
|
||||
#[derive(Debug)]
|
||||
struct KeyTypeTuple {
|
||||
message_key: String,
|
||||
message_type: SsbMessageContentType,
|
||||
};
|
||||
let mut history_stream = sbot_client.create_history_stream(author.to_string()).await?;
|
||||
let type_stream = history_stream.map(|msg| {
|
||||
match msg {
|
||||
Ok(val) => {
|
||||
let message_type = val.get_message_type()?;
|
||||
let tuple = KeyTypeTuple {
|
||||
message_key: val.signature,
|
||||
message_type: message_type,
|
||||
};
|
||||
Ok(tuple)
|
||||
}
|
||||
Err(err) => {
|
||||
Err(err)
|
||||
}
|
||||
}
|
||||
});
|
||||
pin_mut!(type_stream); // needed for iteration
|
||||
println!("looping through type stream");
|
||||
while let Some(res) = type_stream.next().await {
|
||||
match res {
|
||||
Ok(value) => {
|
||||
println!("value: {:?}", value);
|
||||
},
|
||||
Err(err) => {
|
||||
println!("err: {:?}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
println!("reached end of type stream");
|
||||
|
||||
// return Ok
|
||||
Ok(())
|
||||
// // create a history stream and convert it into a Vec<SsbMessageValue> using try_collect
|
||||
// // (if there is any error in the results, it will be raised)
|
||||
// let mut history_stream = sbot_client.create_history_stream(author.to_string()).await?;
|
||||
// let results : Vec<SsbMessageValue> = history_stream.try_collect().await?;
|
||||
// for x in results {
|
||||
// println!("x: {:?}", x);
|
||||
// }
|
||||
//
|
||||
// // example to create a history stream and use a map to convert stream of SsbMessageValue
|
||||
// // into a stream of KeyTypeTuple (local struct for storing message_key and message_type)
|
||||
// #[derive(Debug)]
|
||||
// struct KeyTypeTuple {
|
||||
// message_key: String,
|
||||
// message_type: SsbMessageContentType,
|
||||
// };
|
||||
// let mut history_stream = sbot_client.create_history_stream(author.to_string()).await?;
|
||||
// let type_stream = history_stream.map(|msg| {
|
||||
// match msg {
|
||||
// Ok(val) => {
|
||||
// let message_type = val.get_message_type()?;
|
||||
// let tuple = KeyTypeTuple {
|
||||
// message_key: val.signature,
|
||||
// message_type: message_type,
|
||||
// };
|
||||
// Ok(tuple)
|
||||
// }
|
||||
// Err(err) => {
|
||||
// Err(err)
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// pin_mut!(type_stream); // needed for iteration
|
||||
// println!("looping through type stream");
|
||||
// while let Some(res) = type_stream.next().await {
|
||||
// match res {
|
||||
// Ok(value) => {
|
||||
// println!("value: {:?}", value);
|
||||
// },
|
||||
// Err(err) => {
|
||||
// println!("err: {:?}", err);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// println!("reached end of type stream");
|
||||
//
|
||||
// // return Ok
|
||||
// Ok(())
|
||||
}
|
||||
|
||||
#[async_std::main]
|
||||
|
|
|
@ -62,11 +62,11 @@ impl SsbMessageValue {
|
|||
|
||||
/// Helper function which returns true if this message is of the given type,
|
||||
/// and false if the type does not match or is not found
|
||||
pub fn is_message_type(&self, message_type: SsbMessageContentType) -> bool {
|
||||
pub fn is_message_type(&self, _message_type: SsbMessageContentType) -> bool {
|
||||
let self_message_type = self.get_message_type();
|
||||
match self_message_type {
|
||||
Ok(mtype) => {
|
||||
matches!(mtype, message_type)
|
||||
matches!(mtype, _message_type)
|
||||
}
|
||||
Err(_err) => {
|
||||
false
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//! Sbot type and associated methods.
|
||||
use std::fmt::Debug;
|
||||
use async_std::net::TcpStream;
|
||||
use futures::pin_mut;
|
||||
|
||||
use async_std::stream::{Stream, StreamExt};
|
||||
use async_stream::stream;
|
||||
|
||||
|
|
12
src/utils.rs
12
src/utils.rs
|
@ -1,12 +1,12 @@
|
|||
//! Utility methods for `golgi`.
|
||||
use async_std::io::Read;
|
||||
use std::fmt::Debug;
|
||||
use async_std::task;
|
||||
use std::time::Duration;
|
||||
use async_std::net::TcpStream;
|
||||
use async_std::stream::Stream;
|
||||
use async_stream::stream;
|
||||
use rand::distributions::{Distribution, Uniform};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
use kuska_ssb::rpc::{RecvMsg, RequestNo, RpcReader};
|
||||
use serde_json::Value;
|
||||
|
|
Loading…
Reference in New Issue