Snippet parser
The snippets file format is a human-readable format for storing strings, which makes it perfect for developpers.
For more information on the format, see the snippets spec.
Example of a snippet file
-- my snippet --
This snippet contains a string
-- end --
Text here is ignored, so it can be used to write comments
-- my second snippet --
This snippet contains multiple lines --
-- end --
About this parser
This is a snippet parser written in Rust. It can be used to both read and write snippets. When reading snippets from a file, they are only read into memory as needed.
Overview
In this section we will define snippets.snip
as:
-- snippet1 --
Are we human?
Or are we dancer?
-- end --
-- snippet2 --
This is my church.
This is where I heal my hurts.
-- end --
This is a comment
-- snippet3 --
Never gonna give you up
Never gonna let you down
Never gonna run around and desert you
Never gonna make you cry
Never gonna say goodbye
Never gonna tell a lie and hurt you
-- end --
Reading from a file
let parser = read.unwrap;
Now that we have a parser, we have some possibilities to read snippets:
Iterator
assert_eq!;
OR
let snippets = vec!;
let snippets_from_iterator = parser.into_iter.map.;
assert_eq!;
Get snippets
assert_eq!;
Get snippet with title
assert_eq!;
Adding snippets to the parser
You can add a snippet to a parser using:
parser.add_snippet;
You can also create an empty parser and add snippets to it, or initialize a parser directly with snippets.
let mut parser1 = new;
parser1.add_snippet;
let parser2 = from_snippets;
assert_eq!;
Saving to a new file
// Get file contents
let file_contents = parser.to_string;
// Write file
let f = new
.append
.open
.expect;
let mut f = new;
f.write_all.expect;
Installing
This crate is published to crates.io, so just add the following to your cargo.toml:
= "0.1.0"
Contributing
There are a lot of optimizations that can be made to this crate, so feel free to open an issue and a pull request. Just make sure the tests are working.
License
This crate is licensed under the MIT license