petname_macros/lib.rs
1use proc_macro::TokenStream;
2
3mod input;
4mod lang;
5mod paths;
6mod text;
7
8/// Construct an English petname generator from word list files at compile time.
9///
10/// Word list files should be UTF-8, with words delimited by whitespace.
11///
12/// ⚠️ Note when reading the examples that all non-absolute paths are ultimately
13/// resolved relative to the build-time `CARGO_MANIFEST_DIR`, i.e. the directory
14/// of `Cargo.toml` for the crate being compiled.
15///
16/// # Examples
17///
18/// Given a directory path it will look for `adjectives.txt`, `adverbs.txt`, and
19/// `nouns.txt` within that directory:
20///
21/// ```ignore
22/// let p = petname::petnames!("words/small");
23/// ```
24///
25/// One can specify each file path explicitly too:
26///
27/// ```ignore
28/// let p = petname::petnames!(
29/// adjectives = "words/small/adjectives.txt",
30/// adverbs = "words/medium/adverbs.txt",
31/// nouns = "words/large/nouns.txt",
32/// );
33/// ```
34///
35/// Given both a directory path and individual paths, the files' paths are
36/// resolved relative to the directory:
37///
38/// ```ignore
39/// let p = petname::petnames!(
40/// "words",
41/// adjectives = "small/adjectives.txt",
42/// adverbs = "medium/adverbs.txt",
43/// nouns = "large/nouns.txt",
44/// );
45/// ```
46///
47/// It is not necessary to specify all of the paths. This will look for
48/// `adjectives.txt`, `adverbs.txt`, and `cars.txt` in the `words/other`
49/// directory:
50///
51/// ```ignore
52/// let p = petname::petnames!("words/other", nouns = "cars.txt");
53/// ```
54///
55/// It is not necessary to specify _any_ of the paths. This will look for
56/// `adjectives.txt`, `adverbs.txt`, and `nouns.txt` in the crate root
57/// directory:
58///
59/// ```ignore
60/// let p = petname::petnames!();
61/// ```
62///
63#[proc_macro]
64pub fn english(input: TokenStream) -> TokenStream {
65 crate::lang::english::expand(input)
66}
67
68/// Construct a Turkish petname generator from word list files at compile time.
69///
70/// Like [`english!`], but for `petname::lang::Turkish`. The adjectives file
71/// uses the same whitespace-delimited format, except a token may carry an
72/// emphatic (reduplicated) form after an `=`, e.g. `kırmızı=kıpkırmızı`. The
73/// adverbs and nouns files are plain whitespace-delimited words.
74///
75/// ```ignore
76/// let t = petname::turkish!("words/turkish");
77/// ```
78#[proc_macro]
79pub fn turkish(input: TokenStream) -> TokenStream {
80 crate::lang::turkish::expand(input)
81}
82
83/// Alias for [`english!`].
84#[proc_macro]
85pub fn petnames(input: TokenStream) -> TokenStream {
86 crate::lang::english::expand(input)
87}