Skip to content

Commit 478683e

Browse files
committed
Fix various linting errors
1 parent c7ec594 commit 478683e

File tree

14 files changed

+82
-122
lines changed

14 files changed

+82
-122
lines changed

cli/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ fn main() -> AtomicResult<()> {
109109
)
110110
.arg(Arg::new("as")
111111
.long("as")
112-
.possible_values(&SERIALIZE_OPTIONS)
112+
.possible_values(SERIALIZE_OPTIONS)
113113
.default_value("pretty")
114114
.help("Serialization format")
115115
.takes_value(true)
@@ -138,7 +138,7 @@ fn main() -> AtomicResult<()> {
138138
)
139139
.arg(Arg::new("as")
140140
.long("as")
141-
.possible_values(&SERIALIZE_OPTIONS)
141+
.possible_values(SERIALIZE_OPTIONS)
142142
.default_value("pretty")
143143
.help("Serialization format")
144144
.takes_value(true)
@@ -282,7 +282,7 @@ fn exec_command(context: &mut Context) -> AtomicResult<()> {
282282
fn list(context: &mut Context) {
283283
let mut string = String::new();
284284
for (shortname, url) in context.mapping.lock().unwrap().clone().into_iter() {
285-
string.push_str(&*format!(
285+
string.push_str(&format!(
286286
"{0: <15}{1: <10} \n",
287287
shortname.blue().bold(),
288288
url

cli/src/new.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ fn prompt_field(
142142
let re = Regex::new(atomic_lib::values::SLUG_REGEX)?;
143143
match input {
144144
Some(slug) => {
145-
if re.is_match(&*slug) {
145+
if re.is_match(&slug) {
146146
return Ok(Some(slug));
147147
}
148148
println!("Only letters, numbers and dashes - no spaces or special characters.");
149149
return Ok(None);
150150
}
151-
None => (return Ok(None)),
151+
None => return Ok(None),
152152
}
153153
}
154154
DataType::Integer => {
@@ -158,7 +158,7 @@ fn prompt_field(
158158
Some(nr) => {
159159
input = Some(nr.to_string());
160160
}
161-
None => (return Ok(None)),
161+
None => return Ok(None),
162162
}
163163
}
164164
DataType::Float => {
@@ -168,7 +168,7 @@ fn prompt_field(
168168
Some(nr) => {
169169
input = Some(nr.to_string());
170170
}
171-
None => (return Ok(None)),
171+
None => return Ok(None),
172172
}
173173
}
174174
DataType::Date => {
@@ -177,14 +177,14 @@ fn prompt_field(
177177
let re = Regex::new(atomic_lib::values::DATE_REGEX).unwrap();
178178
match date {
179179
Some(date_val) => {
180-
if re.is_match(&*date_val) {
180+
if re.is_match(&date_val) {
181181
input = Some(date_val);
182182
return Ok(input);
183183
}
184184
println!("Not a valid date.");
185185
return Ok(None);
186186
}
187-
None => (return Ok(None)),
187+
None => return Ok(None),
188188
}
189189
}
190190
DataType::AtomicUrl => loop {
@@ -264,7 +264,7 @@ fn prompt_field(
264264
Some(nr) => {
265265
input = Some(nr.to_string());
266266
}
267-
None => (return Ok(None)),
267+
None => return Ok(None),
268268
}
269269
}
270270
DataType::Unsupported(unsup) => {
@@ -277,7 +277,7 @@ fn prompt_field(
277277
Some(nr) => {
278278
input = Some(nr);
279279
}
280-
None => (return Ok(None)),
280+
None => return Ok(None),
281281
}
282282
}
283283
DataType::Boolean => {
@@ -290,7 +290,7 @@ fn prompt_field(
290290
}
291291
return Ok(Some("false".to_string()));
292292
}
293-
None => (return Ok(None)),
293+
None => return Ok(None),
294294
}
295295
}
296296
};

cli/src/print.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ pub const SERIALIZE_OPTIONS: [&str; 7] =
1616
pub fn get_serialization(argmatches: &ArgMatches) -> AtomicResult<Format> {
1717
let format = if let Some(preferred_format) = argmatches.value_of("as") {
1818
match preferred_format {
19-
"pretty" => (Format::Pretty),
20-
"json" => (Format::Json),
21-
"jsonld" => (Format::JsonLd),
22-
"jsonad" => (Format::JsonAd),
23-
"nt" => (Format::NTriples),
24-
"turtle" => (Format::NTriples),
25-
"n3" => (Format::NTriples),
19+
"pretty" => Format::Pretty,
20+
"json" => Format::Json,
21+
"jsonld" => Format::JsonLd,
22+
"jsonad" => Format::JsonAd,
23+
"nt" => Format::NTriples,
24+
"turtle" => Format::NTriples,
25+
"n3" => Format::NTriples,
2626
format => {
2727
return Err(
2828
format!("As {} not supported. Try {:?}", format, SERIALIZE_OPTIONS).into(),
@@ -38,14 +38,14 @@ pub fn get_serialization(argmatches: &ArgMatches) -> AtomicResult<Format> {
3838
/// Prints a resource for the terminal with readble formatting and colors
3939
pub fn pretty_print_resource(resource: &Resource, store: &impl Storelike) -> AtomicResult<String> {
4040
let mut output = String::new();
41-
output.push_str(&*format!(
41+
output.push_str(&format!(
4242
"{0: <15}{1: <10} \n",
4343
"subject".blue().bold(),
4444
resource.get_subject()
4545
));
4646
for (prop_url, val) in resource.get_propvals() {
4747
let prop_shortname = store.get_property(prop_url)?.shortname;
48-
output.push_str(&*format!(
48+
output.push_str(&format!(
4949
"{0: <15}{1: <10} \n",
5050
prop_shortname.blue().bold(),
5151
val

lib/src/agents.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ fn generate_keypair() -> AtomicResult<Pair> {
9393
.map_err(|e| format!("Error generating keypair {}", e))
9494
.unwrap();
9595
Ok(Pair {
96-
private: base64::encode(&seed),
97-
public: base64::encode(&key_pair.public_key()),
96+
private: base64::encode(seed),
97+
public: base64::encode(key_pair.public_key()),
9898
})
9999
}
100100

lib/src/db.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ impl Storelike for Db {
562562
let remove_atom = crate::Atom::new(subject.into(), prop.clone(), val.clone());
563563
self.remove_atom_from_index(&remove_atom, &resource)?;
564564
}
565-
let _found = self.resources.remove(&subject.as_bytes())?;
565+
let _found = self.resources.remove(subject.as_bytes())?;
566566
} else {
567567
return Err(format!(
568568
"Resource {} could not be deleted, because it was not found in the store.",
@@ -695,7 +695,7 @@ fn add_atom_to_reference_index(index_atom: &IndexAtom, store: &Db) -> AtomicResu
695695
fn delete_atom_from_reference_index(index_atom: &IndexAtom, store: &Db) -> AtomicResult<()> {
696696
store
697697
.reference_index
698-
.remove(&key_for_reference_index(index_atom).as_bytes())?;
698+
.remove(key_for_reference_index(index_atom).as_bytes())?;
699699
Ok(())
700700
}
701701

lib/src/db/query_index.rs

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -150,44 +150,6 @@ pub fn watch_collection(store: &Db, q_filter: &QueryFilter) -> AtomicResult<()>
150150
Ok(())
151151
}
152152

153-
/// Initialize the index for Collections
154-
// TODO: This is probably no the most reliable way of finding the collections to watch.
155-
// I suppose we should add these dynamically when a Collection is being requested.
156-
#[tracing::instrument(skip(store))]
157-
pub fn create_watched_collections(store: &Db) -> AtomicResult<()> {
158-
let collections_url = format!("{}/collections", store.server_url);
159-
let collections_resource = store.get_resource_extended(&collections_url, false, None)?;
160-
for member_subject in collections_resource
161-
.get(crate::urls::COLLECTION_MEMBERS)?
162-
.to_subjects(None)?
163-
{
164-
let collection = store.get_resource_extended(&member_subject, false, None)?;
165-
let value = if let Ok(val) = collection.get(crate::urls::COLLECTION_VALUE) {
166-
// TODO: check the datatype. Now we assume it's a string
167-
Some(val.clone())
168-
} else {
169-
None
170-
};
171-
let property = if let Ok(val) = collection.get(crate::urls::COLLECTION_PROPERTY) {
172-
Some(val.to_string())
173-
} else {
174-
None
175-
};
176-
let sort_by = if let Ok(val) = collection.get(crate::urls::COLLECTION_SORT_BY) {
177-
Some(val.to_string())
178-
} else {
179-
None
180-
};
181-
let q_filter = QueryFilter {
182-
property,
183-
value,
184-
sort_by,
185-
};
186-
watch_collection(store, &q_filter)?;
187-
}
188-
Ok(())
189-
}
190-
191153
/// Checks if the resource will match with a QueryFilter.
192154
/// Does any value or property or sort value match?
193155
/// Returns the matching property, if found.

lib/src/errors.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub type AtomicResult<T> = std::result::Result<T, AtomicError>;
2121
pub struct AtomicError {
2222
pub message: String,
2323
pub error_type: AtomicErrorType,
24+
pub subject: Option<String>,
2425
}
2526

2627
#[derive(Debug, Clone)]
@@ -44,6 +45,7 @@ impl AtomicError {
4445
AtomicError {
4546
message: format!("Resource not found. {}", message),
4647
error_type: AtomicErrorType::NotFoundError,
48+
subject: None,
4749
}
4850
}
4951

@@ -52,6 +54,7 @@ impl AtomicError {
5254
AtomicError {
5355
message: format!("Unauthorized. {}", message),
5456
error_type: AtomicErrorType::UnauthorizedError,
57+
subject: None,
5558
}
5659
}
5760

@@ -60,6 +63,7 @@ impl AtomicError {
6063
AtomicError {
6164
message,
6265
error_type: AtomicErrorType::OtherError,
66+
subject: None,
6367
}
6468
}
6569

@@ -80,6 +84,7 @@ impl AtomicError {
8084

8185
AtomicError {
8286
message: msg,
87+
subject: None,
8388
error_type: AtomicErrorType::ParseErrror,
8489
}
8590
}
@@ -105,6 +110,7 @@ impl From<&str> for AtomicError {
105110
AtomicError {
106111
message: message.into(),
107112
error_type: AtomicErrorType::OtherError,
113+
subject: None,
108114
}
109115
}
110116
}
@@ -113,6 +119,7 @@ impl From<String> for AtomicError {
113119
fn from(message: String) -> Self {
114120
AtomicError {
115121
message,
122+
subject: None,
116123
error_type: AtomicErrorType::OtherError,
117124
}
118125
}
@@ -122,6 +129,7 @@ impl From<std::boxed::Box<dyn std::error::Error>> for AtomicError {
122129
fn from(error: std::boxed::Box<dyn std::error::Error>) -> Self {
123130
AtomicError {
124131
message: error.to_string(),
132+
subject: None,
125133
error_type: AtomicErrorType::OtherError,
126134
}
127135
}
@@ -133,6 +141,7 @@ impl<T> From<std::sync::PoisonError<T>> for AtomicError {
133141
AtomicError {
134142
message: error.to_string(),
135143
error_type: AtomicErrorType::OtherError,
144+
subject: None,
136145
}
137146
}
138147
}
@@ -141,6 +150,7 @@ impl From<std::io::Error> for AtomicError {
141150
fn from(error: std::io::Error) -> Self {
142151
AtomicError {
143152
message: error.to_string(),
153+
subject: None,
144154
error_type: AtomicErrorType::OtherError,
145155
}
146156
}
@@ -151,6 +161,7 @@ impl From<url::ParseError> for AtomicError {
151161
AtomicError {
152162
message: error.to_string(),
153163
error_type: AtomicErrorType::OtherError,
164+
subject: None,
154165
}
155166
}
156167
}
@@ -160,6 +171,7 @@ impl From<serde_json::Error> for AtomicError {
160171
AtomicError {
161172
message: error.to_string(),
162173
error_type: AtomicErrorType::OtherError,
174+
subject: None,
163175
}
164176
}
165177
}
@@ -169,6 +181,7 @@ impl From<std::string::FromUtf8Error> for AtomicError {
169181
AtomicError {
170182
message: error.to_string(),
171183
error_type: AtomicErrorType::OtherError,
184+
subject: None,
172185
}
173186
}
174187
}
@@ -178,6 +191,7 @@ impl From<ParseFloatError> for AtomicError {
178191
AtomicError {
179192
message: error.to_string(),
180193
error_type: AtomicErrorType::OtherError,
194+
subject: None,
181195
}
182196
}
183197
}
@@ -186,6 +200,7 @@ impl From<ParseIntError> for AtomicError {
186200
fn from(error: ParseIntError) -> Self {
187201
AtomicError {
188202
message: error.to_string(),
203+
subject: None,
189204
error_type: AtomicErrorType::OtherError,
190205
}
191206
}
@@ -196,6 +211,7 @@ impl From<DecodeError> for AtomicError {
196211
AtomicError {
197212
message: error.to_string(),
198213
error_type: AtomicErrorType::OtherError,
214+
subject: None,
199215
}
200216
}
201217
}
@@ -204,6 +220,7 @@ impl From<ParseBoolError> for AtomicError {
204220
fn from(error: ParseBoolError) -> Self {
205221
AtomicError {
206222
message: error.to_string(),
223+
subject: None,
207224
error_type: AtomicErrorType::OtherError,
208225
}
209226
}
@@ -214,6 +231,7 @@ impl From<Infallible> for AtomicError {
214231
AtomicError {
215232
message: error.to_string(),
216233
error_type: AtomicErrorType::OtherError,
234+
subject: None,
217235
}
218236
}
219237
}
@@ -224,6 +242,7 @@ impl From<sled::Error> for AtomicError {
224242
AtomicError {
225243
message: error.to_string(),
226244
error_type: AtomicErrorType::OtherError,
245+
subject: None,
227246
}
228247
}
229248
}
@@ -233,6 +252,7 @@ impl From<Box<bincode::ErrorKind>> for AtomicError {
233252
fn from(error: Box<bincode::ErrorKind>) -> Self {
234253
AtomicError {
235254
message: error.to_string(),
255+
subject: None,
236256
error_type: AtomicErrorType::OtherError,
237257
}
238258
}

lib/src/mapping.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl Mapping {
8686
let mut file_string: String = String::new();
8787
for (key, url) in self.hashmap.clone().iter() {
8888
let map = format!("{}={}\n", key, url);
89-
file_string.push_str(&*map);
89+
file_string.push_str(&map);
9090
}
9191
fs::create_dir_all(path.parent().expect("Cannot create above root"))
9292
.expect("Unable to create dirs");

0 commit comments

Comments
 (0)