aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2022-11-06 20:52:54 -0800
committerBryan Newbold <bnewbold@robocracy.org>2022-11-06 20:52:54 -0800
commit3320e8fa5d120b8bc4917152114cf78cb0e504dc (patch)
tree0249e18d462740b174a6ce5c5a0322f63a6d5c8f
parent2641389cb74939df9090a8183ec67ab0558f0b06 (diff)
downloadadenosine-3320e8fa5d120b8bc4917152114cf78cb0e504dc.tar.gz
adenosine-3320e8fa5d120b8bc4917152114cf78cb0e504dc.zip
cli: partial clippy cleanups
-rw-r--r--adenosine-cli/src/bin/adenosine.rs15
-rw-r--r--adenosine-cli/src/lib.rs10
2 files changed, 11 insertions, 14 deletions
diff --git a/adenosine-cli/src/bin/adenosine.rs b/adenosine-cli/src/bin/adenosine.rs
index 0062763..8b937bc 100644
--- a/adenosine-cli/src/bin/adenosine.rs
+++ b/adenosine-cli/src/bin/adenosine.rs
@@ -294,7 +294,7 @@ fn run(opt: Opt) -> Result<()> {
.map(|v| v.to_string())
.or(jwt_did)
.ok_or(anyhow!("expected a name, or self via auth token"))?;
- params.insert("user".to_string(), name.to_string());
+ params.insert("user".to_string(), name);
xrpc_client.get("com.atproto.repoDescribe", Some(params))?
}
Command::Resolve { name } => {
@@ -320,7 +320,7 @@ fn run(opt: Opt) -> Result<()> {
Command::Ls { uri } => {
// TODO: option to print fully-qualified path?
params.insert("user".to_string(), uri.repository.to_string());
- if !uri.collection.is_some() {
+ if uri.collection.is_none() {
// if a repository, but no collection, list the collections
let describe = xrpc_client
.get("com.atproto.repoDescribe", Some(params))?
@@ -331,17 +331,14 @@ fn run(opt: Opt) -> Result<()> {
{
println!(
"at://{}/{}",
- uri.repository.to_string(),
+ uri.repository,
c.as_str()
.ok_or(anyhow!("expected collection as a JSON string"))?
);
}
- } else if uri.collection.is_some() && !uri.record.is_some() {
+ } else if uri.collection.is_some() && uri.record.is_none() {
// if a collection, but no record, list the records (with extracted timestamps)
- params.insert(
- "collection".to_string(),
- uri.collection.unwrap().to_string(),
- );
+ params.insert("collection".to_string(), uri.collection.unwrap());
let records = xrpc_client
.get("com.atproto.repoListRecords", Some(params))?
.ok_or(anyhow!("expected a repoListRecords response"))?;
@@ -573,7 +570,7 @@ fn run(opt: Opt) -> Result<()> {
.map(|v| v.to_string())
.or(jwt_did)
.ok_or(anyhow!("expected a name, or self via auth token"))?;
- params.insert("user".to_string(), name.to_string());
+ params.insert("user".to_string(), name);
xrpc_client.get("app.bsky.getProfile", Some(params))?
}
Command::Bsky {
diff --git a/adenosine-cli/src/lib.rs b/adenosine-cli/src/lib.rs
index 8dbfa6c..f05a865 100644
--- a/adenosine-cli/src/lib.rs
+++ b/adenosine-cli/src/lib.rs
@@ -58,7 +58,7 @@ impl XrpcClient {
nsid: &str,
params: Option<HashMap<String, String>>,
) -> Result<Option<Value>> {
- let params: HashMap<String, String> = params.unwrap_or(HashMap::new());
+ let params: HashMap<String, String> = params.unwrap_or_default();
let res = self
.http_client
.get(format!("{}/xrpc/{}", self.host, nsid))
@@ -88,7 +88,7 @@ impl XrpcClient {
params: Option<HashMap<String, String>>,
output: &mut W,
) -> Result<u64> {
- let params: HashMap<String, String> = params.unwrap_or(HashMap::new());
+ let params: HashMap<String, String> = params.unwrap_or_default();
let res = self
.http_client
.get(format!("{}/xrpc/{}", self.host, nsid))
@@ -117,7 +117,7 @@ impl XrpcClient {
params: Option<HashMap<String, String>>,
body: Option<Value>,
) -> Result<Option<Value>> {
- let params: HashMap<String, String> = params.unwrap_or(HashMap::new());
+ let params: HashMap<String, String> = params.unwrap_or_default();
let mut req = self
.http_client
.post(format!("{}/xrpc/{}", self.host, nsid))
@@ -155,7 +155,7 @@ impl XrpcClient {
params: Option<HashMap<String, String>>,
input: &mut R,
) -> Result<Option<Value>> {
- let params: HashMap<String, String> = params.unwrap_or(HashMap::new());
+ let params: HashMap<String, String> = params.unwrap_or_default();
let mut buf: Vec<u8> = Vec::new();
input.read_to_end(&mut buf)?;
let res = self
@@ -181,7 +181,7 @@ impl XrpcClient {
/// Tries to parse a DID internal identifier from a JWT (as base64-encoded token)
pub fn parse_did_from_jwt(jwt: &str) -> Result<String> {
- let second_b64 = jwt.split(".").nth(1).ok_or(anyhow!("couldn't parse JWT"))?;
+ let second_b64 = jwt.split('.').nth(1).ok_or(anyhow!("couldn't parse JWT"))?;
let second_json: Vec<u8> = base64::decode_config(second_b64, base64::URL_SAFE)?;
let obj: Value = serde_json::from_slice(&second_json)?;
// trying to also support pulling "aud" as DID; not sure this is actually correct use of