base_custom/
lib.rs

1// Copyright 2017 Daniel P. Clark & base_custom Developers
2// 
3// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
4// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5// http://opensource.org/licenses/MIT>, at your option. This file may not be
6// copied, modified, or distributed except according to those terms.
7#![deny(missing_docs,trivial_casts,trivial_numeric_casts,
8        missing_debug_implementations, missing_copy_implementations,
9        unsafe_code,unstable_features,unused_import_braces,unused_qualifications)
10]
11//! # base_custom
12//!
13//! allows you to use any set of characters as your own numeric base and convert
14//! to and from decimal.  This can be taken advantage of in various ways:
15//!
16//! * Mathematics: number conversion
17//!
18//! * Brute force sequencing
19//!
20//! * Rolling ciphers
21//!
22//! * Moderate information concealment
23//!
24//! * Other potential uses such as deriving music or art from numbers
25//!
26//! ## To Include It
27//!
28//! Add `base_custom` to your dependencies section of your `Cargo.toml` file.
29//!
30//! ```text
31//! [dependencies]
32//! base_custom = "^0.1"
33//! ```
34//!
35//! In your rust files where you plan to use it put this at the top
36//!
37//! ```text
38//! extern crate base_custom;
39//! use base_custom::BaseCustom;
40//! ```
41//!
42//! This is licensed under MIT or APACHE 2.0 at your option.
43
44use std::collections::HashMap;
45
46/// The BaseCustom struct holds the information to perform number conversions
47/// via the `gen` and `decimal` methods.
48///
49/// A new instance of BaseCustom can be created with either
50///
51/// * `BaseCustom::<char>::new(Vec<char>)`
52/// * `BaseCustom::<char>::from_ordinal_range(Range)`
53/// * `BaseCustom::<String>::new(String, Option<char>)`
54///
55/// _If you are going to provide a delimiter you need to use the `<String>` implementation.
56/// A delimiter is optional._
57///
58/// The primitives for BaseCustom get built from the provides characters or string groups
59/// and conversion methods are available to use then.  String groupings will be single character
60/// strings if no delimiter is given, otherwise they may be strings of any length split only
61/// by the delimiter provided.
62#[derive(Clone)]
63pub struct BaseCustom<T> {
64  primitives: Vec<T>,
65  primitives_hash: HashMap<T, u8>,
66  /// The size of the base
67  pub base: u64,
68  delim: Option<char>,
69}
70
71mod u8;
72mod char;
73mod string;
74mod util;
75
76pub use crate::u8::*;
77pub use crate::char::*;
78pub use crate::string::*;