#file-format #tsv #read-write #macos-ios #serialize-deserialize #json #json-file

bcheck

library that can read and write bcheck and tsv files, which are generated by BCheckbook for iOS and Mac

8 releases

0.3.3 Nov 13, 2023
0.3.2 May 18, 2023
0.3.0 Jan 14, 2022
0.2.2 Jul 26, 2021
0.1.0 Jul 18, 2021

#2041 in Parser implementations

MIT license

38KB
563 lines

=bcheck=

'''Author:''' Bryce Campbell

'''License:''' See LICENSE

'''Description:''' A crate for Rust that allows one to read and write bcheck files generated by BCheckbook.

'''Version:''' 0.3.3

==Notes==

This crate has been tested with Rust 1.59.0 on macOS and with Rust on Windows. It is not known if it will work in earlier versions, though it should if the dependencies are also backwards compatible.

===Why Create this library===

After having made an application that could serve as a Checkbook ledger, I thought it would be nice to create a way to read and write the saves in Rust, so that I can create an applications for application besides macOS and iOS, as well as learn more about serde, to see if I can customize serialization and deserialization as much as I could with Codable in Swift, and hopefully save others time figuring out how those files are read properly.

While it might be sometime before I can actually use this code to do anything, due to the current state of GUI programming with Rust and the fact that I implemented something I am having troubles with on iOS, things should be very much usable.

===Version History===

0.1
Initial release. Released 7/18/2021
0.2

Made it easier to create record objects, so that dependencies do not need to be exposed, and remove unneeded re exports.

Released 7/19/2021

0.2.1

Make it possible to parse transaction type from string. Released 7/23/2021

0.2.2

Add extension trait that adds method to String and str to make getting dates easier. Released 7/26/2021

0.3

Update Transaction model to reflect the current state of the bcheck format.

Released 1/13/2022

0.3.1

Add TSV importing and exporting support, by implementing way to create items with tab delimited strings.

Released 5/17/2023

0.3.2

Fix TSV support, due to method not being found.

Released 5/18/2023

0.3.3

Fix documentation a bit and work on making sure TSV support runs as desired.

Please note that unit tests may need be ran twice because the TSV reading test fails if there is no file and tests are completed randomly.

Released 11/13/2023

===Usage===

To use this library, add the following to your Cargo.toml file:

[dependencies]
bcheck = "0.3"

Afterwards, it is as simple as putting in something like this, if you just need the Record type:

use bcheck::Record;

There ae two other types that can be used when needed, which are Transaction and TransactionType.

These three should provide everything needed to parse bcheck files properly and do operations on them in code.

====Saving Data====

To save Data, the only thing that should be needed is to import the Save trait, in addition to the Record type, which will enable a save method on vectors of type Vec.

This can done like this:

use bcheck::{ Record, Save }

Afterwards, it can be called like this:

let records = vec![Record::new()];

if let Err(error) = records.save("/Users/bob/Documents/example.bcheck") {
    println!("{}", error)
}

TSV data can be saved by using the save_tsv() method instead and is similar to what you see above.

====Loading Data====

To load Data, the only thing that should be needed is to load the record type and use one of te following:

if let Ok(records) = Record::from_file("/Users/bob/Documents/example.bcheck") {
    print!("{}", records[0])
}

This loads from a json file.

if let Ok(records) = Record::from_tsv_file("/Users/bob/Documents/example.bcheck") {
    print!("{}", records[0])
}

This loads records from a TSV file.

Please note that TSV support was coded in a way that it expects 9 columns in total, though some fields can be empty.

As such, it is recommended that you produce the TSV in MS Excel or LibreOffice, so that you can verify that you have the appropriate number of tabs.

===Creating Date objects===

If you import the LocalDateTimeStringExt trait, dates can be created like this:

"2021-7-26".local_dateime().unwrap()

===Contributing===

If you think you can help make this crate better, feel free to fork this project and make a pull request.

Like the BCheckbook program, I will test the changes, to see if they work as they should.

===Support===

Due to my limited Rust experience, in comparison to my experience with Rust, I cannot provide much support, so expect to be on your own.

However, I can try to check things out, so feel free to contact me at the email below:

tonyhawk2100@gmail.com

Dependencies

~4–6.5MB
~116K SLoC