Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove json dependency #2

Open
Feliix42 opened this issue Jul 9, 2018 · 0 comments
Open

Remove json dependency #2

Feliix42 opened this issue Jul 9, 2018 · 0 comments

Comments

@Feliix42
Copy link
Member

Feliix42 commented Jul 9, 2018

As this is the core library I would prefer keeping its size minimal. Pulling in two different json crates seems kind of counterintuitive, now that serde is at 1.0 and stable.

We should remove the json dependency and try to replace the code block below with code that uses serde_json instead.

tdo-core/src/tdo.rs

Lines 250 to 293 in 6e5d218

Err(_) => {
println!("I have to do this here");
let mut file = File::open(path).unwrap();
let mut data = String::new();
file.read_to_string(&mut data).unwrap();
let mut json = match parse(&data) {
Ok(content) => content,
Err(_) => {
return Err(ErrorKind::StorageError(storage_error::ErrorKind::FileCorrupted)
.into())
}
};
let mut lists: Vec<TodoList> = vec![];
for outer in json.entries_mut() {
let mut list = TodoList::new(outer.0);
for inner in outer.1.entries_mut() {
let tdo_id = match inner.0.parse::<u32>() {
Ok(id) => id,
Err(_) => return Err(ErrorKind::StorageError(storage_error::ErrorKind::UnableToConvert).into()),
};
let done = match inner.1.pop().as_bool() {
Some(x) => x,
None => return Err(ErrorKind::StorageError(storage_error::ErrorKind::UnableToConvert).into()),
};
let tdo_name = match inner.1.pop().as_str() {
Some(x) => String::from(x),
None => return Err(ErrorKind::StorageError(storage_error::ErrorKind::UnableToConvert).into()),
};
let mut todo = Todo::new(tdo_id, &tdo_name, None);
if done {
todo.set_done();
}
list.add(todo);
}
lists.push(list);
}
let tdo = Tdo {
lists: lists,
access_token: None,
version: env!("CARGO_PKG_VERSION").to_string(),
};
Ok(tdo)

I would propose releasing this as version 0.2.2, which also includes the dependency update I just pushed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant