Skip to content

Commit b7e1c17

Browse files
authored
Update Base64, clippy fixes (#32)
* Update Base64, clippy * Clippy: Display for Actions
1 parent be945ef commit b7e1c17

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

typesense/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ crate-type = ["cdylib", "rlib"]
1919

2020
[dependencies]
2121
async-trait = "0.1"
22-
base64 = "0.13"
22+
base64 = "0.21"
2323
hmac = "0.12"
2424
http = "0.2"
2525
serde = { version = "1", features = ["derive"] }

typesense/src/client/keys.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
//!
33
//! More info [here](https://typesense.org/docs/0.20.0/api/api-keys.html).
44
5+
use base64::{engine::general_purpose::STANDARD as Base64Engine, Engine};
6+
use core::fmt;
57
use hmac::{Hmac, Mac};
68
use serde::{Deserialize, Serialize};
79
use sha2::Sha256;
@@ -96,12 +98,12 @@ where
9698
let mut mac = Hmac::<Sha256>::new_from_slice(key.as_ref().as_bytes()).unwrap();
9799
mac.update(params.as_bytes());
98100
let result = mac.finalize();
99-
let digest = base64::encode(result.into_bytes());
101+
let digest = Base64Engine.encode(result.into_bytes());
100102

101103
let key_prefix = &key.as_ref()[0..4];
102104
let raw_scoped_key = format!("{}{}{}", digest, key_prefix, params);
103105

104-
Ok(base64::encode(raw_scoped_key.as_bytes()))
106+
Ok(Base64Engine.encode(raw_scoped_key.as_bytes()))
105107
}
106108
}
107109

@@ -138,16 +140,16 @@ pub enum Actions {
138140
#[serde(rename = "*")]
139141
All,
140142
}
141-
impl ToString for Actions {
142-
fn to_string(&self) -> String {
143+
impl fmt::Display for Actions {
144+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
143145
match self {
144-
Self::DocumentsAll => "documents:*".to_string(),
145-
Self::DocumentsSearch => "documents:search".to_string(),
146-
Self::DocumentsGet => "documents:get".to_string(),
147-
Self::CollectionsAll => "collections:*".to_string(),
148-
Self::CollectionsDelete => "collections:delete".to_string(),
149-
Self::CollectionsCreate => "collections:create".to_string(),
150-
Self::All => "*".to_string(),
146+
Self::DocumentsAll => write!(f, "documents:*"),
147+
Self::DocumentsSearch => write!(f, "documents:search"),
148+
Self::DocumentsGet => write!(f, "documents:get"),
149+
Self::CollectionsAll => write!(f, "collections:*"),
150+
Self::CollectionsDelete => write!(f, "collections:delete"),
151+
Self::CollectionsCreate => write!(f, "collections:create"),
152+
Self::All => write!(f, "*"),
151153
}
152154
}
153155
}

typesense_derive/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ fn extract_default_sorting_field(attributes: &[Attribute]) -> syn::Result<Option
128128
}
129129
None => {
130130
return Some(Err(syn::Error::new_spanned(
131-
&attr,
131+
attr,
132132
"expected: typesense(default_sorting_field = \"...\")",
133133
)));
134134
}
@@ -146,7 +146,7 @@ fn extract_default_sorting_field(attributes: &[Attribute]) -> syn::Result<Option
146146
}
147147
None => {
148148
return Some(Err(syn::Error::new_spanned(
149-
&attribute_tt,
149+
attribute_tt,
150150
"expected: equal sign(=)",
151151
)));
152152
}
@@ -164,7 +164,7 @@ fn extract_default_sorting_field(attributes: &[Attribute]) -> syn::Result<Option
164164
}
165165
_ => {
166166
return Some(Err(syn::Error::new_spanned(
167-
&eq_sign,
167+
eq_sign,
168168
"Expected string literal",
169169
)))
170170
}
@@ -197,7 +197,7 @@ fn extract_default_sorting_field(attributes: &[Attribute]) -> syn::Result<Option
197197
} else {
198198
Err(syn::Error::new_spanned(
199199
// This will not fail since if we are at this point is because attributes is not empty.
200-
attributes.get(0).unwrap(),
200+
attributes.first().unwrap(),
201201
format!(
202202
"Expected only one default_sorting_field, found {}",
203203
default_sorting_field.len(),
@@ -239,7 +239,7 @@ fn extract_collection_name(attributes: &[Attribute]) -> syn::Result<Option<Strin
239239
}
240240
None => {
241241
return Some(Err(syn::Error::new_spanned(
242-
&attr,
242+
attr,
243243
"expected: typesense(collection_name = \"...\")",
244244
)));
245245
}
@@ -257,7 +257,7 @@ fn extract_collection_name(attributes: &[Attribute]) -> syn::Result<Option<Strin
257257
}
258258
None => {
259259
return Some(Err(syn::Error::new_spanned(
260-
&attribute_tt,
260+
attribute_tt,
261261
"expected: equal sign(=)",
262262
)));
263263
}
@@ -275,7 +275,7 @@ fn extract_collection_name(attributes: &[Attribute]) -> syn::Result<Option<Strin
275275
}
276276
_ => {
277277
return Some(Err(syn::Error::new_spanned(
278-
&eq_sign,
278+
eq_sign,
279279
"Expected string literal",
280280
)))
281281
}
@@ -308,7 +308,7 @@ fn extract_collection_name(attributes: &[Attribute]) -> syn::Result<Option<Strin
308308
} else {
309309
Err(syn::Error::new_spanned(
310310
// This will not fail since if we are at this point is because attributes is not empty.
311-
attributes.get(0).unwrap(),
311+
attributes.first().unwrap(),
312312
format!(
313313
"Expected only one collection_name, found {}",
314314
collection_name.len(),

0 commit comments

Comments
 (0)