conf-embed

Crates.ioconf-embed
lib.rsconf-embed
version0.1.3
sourcesrc
created_at2019-05-18 16:49:54.592152
updated_at2019-05-20 21:36:26.962439
descriptionAn experimental Rust crate for embedding user configuration (or anything really) in the executable of the program.
homepage
repositoryhttps://github.com/matrizx/conf-embed
max_upload_size
id135110
size9,332
Laz H (matrizx)

documentation

README

conf-embed

An experimental Rust crate for embedding user configuration (or anything really) in the executable of the program.

It pretty much does what the description says. It allows you to get and change some data that is stored in the executable of the program, meaning you don't need to use any additional files to store user configuration.

NOTE: This crate is semi-stable, but due to the nature of what it is doing, it is also unsafe. Use with caution.

For example: To use this crate, you would first set a config (this can be any string slice but in this case I am using JSON data):

conf_embed::new_config("{\"arbitrary_data\": \"arbitrary_value\"").unwrap();

When this command is run, a new executable will be produced with the same name as the current one, and the current one will be renamed with .old at the end of it.

For example, if the above code is ran on test.exe, the current test.exe will be renamed to test.exe.old and test.exe will become updated with the new config.

To get the config, simply use:

println!("Current config: '{}'", conf_embed::get_config().unwrap());

This works on all platforms, too.

Also, both functions above return an io::Result<()>, meaning errors can be propagated like such:

use std::io;
use std::process;

fn main() -> io::Result<()> {
	println!("Current config: '{}'", conf_embed::get_config()?);

	println!("Enter a new config:");

	let mut buf = String::new();
	io::stdin().read_line(&mut buf)?;

	println!("Setting new config...");
	conf_embed::new_config(&buf)?;
	println!("Config set, exiting.");
	process::exit(0);
}

There are a few limitations you should know about when using this crate.

To begin, the string ----CONFIG-REF-START---- must not be anywhere in the set config. If it is, Err will be returned.

Also, any sequence of 0's following the end of your config will be ignored. For example: If your config is test test0000000, this will be interpreted as test test.

Finally, the config must be no more than 2024 bytes. This restriction is in place for safety and speed, but also to keep the binary size small.

Commit count: 0

cargo fmt