1
Fork 0
Roman numeral library for Rust. https://crates.io/crates/romantic
Go to file
Bauke 4e92ed4a61
Version 0.1.2!
2024-01-25 13:29:30 +01:00
source Initial commit! 🎉 2022-04-10 16:11:14 +02:00
tests Fix Clippy issues. 2024-01-25 13:21:29 +01:00
.envrc Add Nix flake and direnv files. 2024-01-25 13:04:20 +01:00
.gitignore Update dependencies. 2024-01-25 13:14:44 +01:00
Cargo.toml Version 0.1.2! 2024-01-25 13:29:30 +01:00
LICENSE-Apache Initial commit! 🎉 2022-04-10 16:11:14 +02:00
LICENSE-MIT Update license year. 2024-01-25 13:26:43 +01:00
Makefile.toml Add the cargo-make configuration and Development section. 2024-01-25 13:07:15 +01:00
README.md Add the cargo-make configuration and Development section. 2024-01-25 13:07:15 +01:00
flake.lock Add Nix flake and direnv files. 2024-01-25 13:04:20 +01:00
flake.nix Add Nix flake and direnv files. 2024-01-25 13:04:20 +01:00
rustfmt.toml Initial commit! 🎉 2022-04-10 16:11:14 +02:00
rustup-toolchain.toml Add Nix flake and direnv files. 2024-01-25 13:04:20 +01:00
shell.nix Add Nix flake and direnv files. 2024-01-25 13:04:20 +01:00
typos.toml Add Nix flake and direnv files. 2024-01-25 13:04:20 +01:00

README.md

Romantic 🏛

Roman numeral library for Rust.

API

For full documentation see docs.rs.

Examples

Using the default Roman numeral system.

use romantic::Roman;

let roman = Roman::default();

assert_eq!(roman.to_string(2022).unwrap(), "MMXXII");
assert_eq!(roman.from_str::<i32>("MMXXII").unwrap(), 2022);

// The default Roman numeral system has a maximum of 3999.
assert!(roman.to_string(4000).is_err());

Using your own custom character set.

use romantic::Roman;

// The order of characters in the array determines their value.
// Here, A equals 1 and B equals 5.
let custom = Roman::new(&['A', 'B']);

assert_eq!(custom.to_string(6).unwrap(), "BA");
assert_eq!(custom.from_str::<i32>("BA").unwrap(), 6);

// With only 2 characters, the maximum value you can get is 8
// (the equivalent of VIII). To increase the maximum range, use
// more characters.
assert!(custom.to_string(9).is_err());

Development

With Nix flakes and direnv installed and enabled, all the required dependencies are automatically loaded from shell.nix. Then cargo-make can be used to build, deploy and lint the code. The available tasks are all described in the Makefile.toml configuration.

Feedback

Found a problem or want to request a new feature? Email helllo@holllo.org and I'll see what I can do for you.

License

Distributed under the Apache License 2.0 and MIT licenses, see LICENSE-Apache and LICENSE-MIT for more information.