Documentation
use std::error::Error;
use std::io;
use std::io::Write;
use std::fs::File;

fn main () {

	match main_real () {

		Ok (_) => (),

		Err (error) => {

			writeln! (
				& mut io::stderr (),
				"{}",
				error,
			).unwrap_or (());

		},

	};

}

fn main_real (
) -> Result <(), String> {

	write_metadata (
	).map_err (
		|io_error|

		format! (
			"Error writing metadata: {}",
			io_error.description ())

	) ?;

	Ok (())

}

fn write_metadata (
) -> Result <(), io::Error> {

	let mut file =
		File::create (
			"src/metadata.rs",
		) ?;

	writeln! (
		& mut file,
		"// WARNING: this file is generated by build.rs, changes will be lost.",
	) ?;

	writeln! (
		& mut file,
		"",
	) ?;

	writeln! (
		& mut file,
		"pub const VERSION: & 'static str = \"{}\";",
		env! ("CARGO_PKG_VERSION"),
	) ?;

	writeln! (
		& mut file,
		"pub const AUTHOR: & 'static str = \"{}\";",
		"James Pharaoh <james@pharaoh.uk>",
	) ?;

	writeln! (
		& mut file,
		"",
	) ?;

	writeln! (
		& mut file,
		"// ex: noet ts=4 filetype=rust",
	) ?;

	Ok (())

}

// ex: noet ts=4 filetype=rust