Inline the word data with a build script.

This gets me back to exactly what I was hoping for: 2 plaintext files
that would be "inlined" into native code which could be statically
built. The build script was the key here. Happy now ;)

Signed-off-by: Fletcher Nichol <fnichol@nichol.ca>
This commit is contained in:
Fletcher Nichol 2016-04-29 19:07:14 -06:00
parent 1b1bcfbd94
commit d9dc0eafbf
7 changed files with 2143 additions and 2116 deletions

View File

@ -13,6 +13,7 @@ A library to generate random name strings suitable for use in container
instances, project names, application instances, etc.
"""
exclude = ["cli"]
build = "build.rs"
[lib]
name = "names"

24
build.rs Normal file
View File

@ -0,0 +1,24 @@
use std::env;
use std::fs::File;
use std::io::{BufReader, BufWriter};
use std::io::prelude::*;
use std::path::Path;
fn main() {
generate(Path::new("data").join("adjectives.txt").as_path(),
Path::new(&env::var("OUT_DIR").unwrap()).join("adjectives.rs").as_path());
generate(Path::new("data").join("nouns.txt").as_path(),
Path::new(&env::var("OUT_DIR").unwrap()).join("nouns.rs").as_path());
}
fn generate(src_path: &Path, dst_path: &Path) {
let src = File::open(src_path).unwrap();
let src = BufReader::new(src);
let dst = File::create(dst_path).unwrap();
let mut dst = BufWriter::new(dst);
write!(dst, "[\n").unwrap();
for word in src.lines() {
write!(dst, "\"{}\",\n", &word.unwrap()).unwrap();
}
write!(dst, "];\n").unwrap();
}

1124
data/adjectives.txt Normal file

File diff suppressed because it is too large Load Diff

981
data/nouns.txt Normal file
View File

@ -0,0 +1,981 @@
able
account
achieve
achiever
acoustics
act
action
activity
actor
addition
adjustment
advertisement
advice
aftermath
afternoon
afterthought
agreement
air
airplane
airport
alarm
alley
amount
amusement
anger
angle
animal
answer
ant
ants
apparatus
apparel
apple
apples
appliance
approval
arch
argument
arithmetic
arm
army
art
attack
attempt
attention
attraction
aunt
authority
babies
baby
back
badge
bag
bait
balance
ball
balloon
balls
banana
band
base
baseball
basin
basket
basketball
bat
bath
battle
bead
beam
bean
bear
bears
beast
bed
bedroom
beds
bee
beef
beetle
beggar
beginner
behavior
belief
believe
bell
bells
berry
bike
bikes
bird
birds
birth
birthday
bit
bite
blade
blood
blow
board
boat
boats
body
bomb
bone
book
books
boot
border
bottle
boundary
box
boy
boys
brain
brake
branch
brass
bread
breakfast
breath
brick
bridge
brother
brothers
brush
bubble
bucket
building
bulb
bun
burn
burst
bushes
business
butter
button
cabbage
cable
cactus
cake
cakes
calculator
calendar
camera
camp
can
cannon
canvas
cap
caption
car
card
care
carpenter
carriage
cars
cart
cast
cat
cats
cattle
cause
cave
celery
cellar
cemetery
cent
chain
chair
chairs
chalk
chance
change
channel
cheese
cherries
cherry
chess
chicken
chickens
children
chin
church
circle
clam
class
clock
clocks
cloth
cloud
clouds
clover
club
coach
coal
coast
coat
cobweb
coil
collar
color
comb
comfort
committee
company
comparison
competition
condition
connection
control
cook
copper
copy
cord
cork
corn
cough
country
cover
cow
cows
crack
cracker
crate
crayon
cream
creator
creature
credit
crib
crime
crook
crow
crowd
crown
crush
cry
cub
cup
current
curtain
curve
cushion
dad
daughter
day
death
debt
decision
deer
degree
design
desire
desk
destruction
detail
development
digestion
dime
dinner
dinosaurs
direction
dirt
discovery
discussion
disease
disgust
distance
distribution
division
dock
doctor
dog
dogs
doll
dolls
donkey
door
downtown
drain
drawer
dress
drink
driving
drop
drug
drum
duck
ducks
dust
ear
earth
earthquake
edge
education
effect
egg
eggnog
eggs
elbow
end
engine
error
event
example
exchange
existence
expansion
experience
expert
eye
eyes
face
fact
fairies
fall
family
fan
fang
farm
farmer
father
faucet
fear
feast
feather
feeling
feet
fiction
field
fifth
fight
finger
fire
fireman
fish
flag
flame
flavor
flesh
flight
flock
floor
flower
flowers
fly
fog
fold
food
foot
force
fork
form
fowl
frame
friction
friend
friends
frog
frogs
front
fruit
fuel
furniture
galley
game
garden
gate
geese
ghost
giants
giraffe
girl
girls
glass
glove
glue
goat
gold
goldfish
good-bye
goose
government
governor
grade
grain
grandfather
grandmother
grape
grass
grip
ground
group
growth
guide
guitar
gun
hair
haircut
hall
hammer
hand
hands
harbor
harmony
hat
hate
head
health
hearing
heart
heat
help
hen
hill
history
hobbies
hole
holiday
home
honey
hook
hope
horn
horse
horses
hose
hospital
hot
hour
house
houses
humor
hydrant
ice
icicle
idea
impulse
income
increase
industry
ink
insect
instrument
insurance
interest
invention
iron
island
jail
jam
jar
jeans
jelly
jellyfish
jewel
join
joke
journey
judge
juice
jump
kettle
key
kick
kiss
kite
kitten
kittens
kitty
knee
knife
knot
knowledge
laborer
lace
ladybug
lake
lamp
land
language
laugh
lawyer
lead
leaf
learning
leather
leg
legs
letter
letters
lettuce
level
library
lift
light
limit
line
linen
lip
liquid
list
lizards
loaf
lock
locket
look
loss
love
low
lumber
lunch
lunchroom
machine
magic
maid
mailbox
man
manager
map
marble
mark
market
mask
mass
match
meal
measure
meat
meeting
memory
men
metal
mice
middle
milk
mind
mine
minister
mint
minute
mist
mitten
mom
money
monkey
month
moon
morning
mother
motion
mountain
mouth
move
muscle
music
nail
name
nation
neck
need
needle
nerve
nest
net
news
night
noise
north
nose
note
notebook
number
nut
oatmeal
observation
ocean
offer
office
oil
operation
opinion
orange
oranges
order
organization
ornament
oven
owl
owner
page
pail
pain
paint
pan
pancake
paper
parcel
parent
park
part
partner
party
passenger
paste
patch
payment
peace
pear
pen
pencil
person
pest
pet
pets
pickle
picture
pie
pies
pig
pigs
pin
pipe
pizzas
place
plane
planes
plant
plantation
plants
plastic
plate
play
playground
pleasure
plot
plough
pocket
point
poison
police
polish
pollution
popcorn
porter
position
pot
potato
powder
power
price
print
prison
process
produce
profit
property
prose
protest
pull
pump
punishment
purpose
push
quarter
quartz
queen
question
quicksand
quiet
quill
quilt
quince
quiver
rabbit
rabbits
rail
railway
rain
rainstorm
rake
range
rat
rate
ray
reaction
reading
reason
receipt
recess
record
regret
relation
religion
representative
request
respect
rest
reward
rhythm
rice
riddle
rifle
ring
rings
river
road
robin
rock
rod
roll
roof
room
root
rose
route
rub
rule
run
sack
sail
salt
sand
scale
scarecrow
scarf
scene
scent
school
science
scissors
screw
sea
seashore
seat
secretary
seed
selection
self
sense
servant
shade
shake
shame
shape
sheep
sheet
shelf
ship
shirt
shock
shoe
shoes
shop
show
side
sidewalk
sign
silk
silver
sink
sister
sisters
size
skate
skin
skirt
sky
slave
sleep
sleet
slip
slope
smash
smell
smile
smoke
snail
snails
snake
snakes
sneeze
snow
soap
society
sock
soda
sofa
son
song
songs
sort
sound
soup
space
spade
spark
spiders
sponge
spoon
spot
spring
spy
square
squirrel
stage
stamp
star
start
statement
station
steam
steel
stem
step
stew
stick
sticks
stitch
stocking
stomach
stone
stop
store
story
stove
stranger
straw
stream
street
stretch
string
structure
substance
sugar
suggestion
suit
summer
sun
support
surprise
sweater
swim
swing
system
table
tail
talk
tank
taste
tax
teaching
team
teeth
temper
tendency
tent
territory
test
texture
theory
thing
things
thought
thread
thrill
throat
throne
thumb
thunder
ticket
tiger
time
tin
title
toad
toe
toes
tomatoes
tongue
tooth
toothbrush
toothpaste
top
touch
town
toy
toys
trade
trail
train
trains
tramp
transport
tray
treatment
tree
trees
trick
trip
trouble
trousers
truck
trucks
tub
turkey
turn
twig
twist
umbrella
uncle
underwear
unit
use
vacation
value
van
vase
vegetable
veil
vein
verse
vessel
vest
view
visitor
voice
volcano
volleyball
voyage
walk
wall
war
wash
waste
watch
water
wave
waves
wax
way
wealth
weather
week
weight
wheel
whip
whistle
wilderness
wind
window
wine
wing
winter
wire
wish
woman
women
wood
wool
word
work
worm
wound
wren
wrench
wrist
writer
writing
yak
yam
yard
yarn
year
yoke
zebra
zephyr
zinc
zipper
zoo

File diff suppressed because it is too large Load Diff

View File

@ -29,7 +29,7 @@
//! ```
//! use names::Generator;
//!
//! let mut generator: Generator = Default::default();
//! let mut generator = Generator::default();
//! println!("Your project is: {}", generator.next().unwrap());
//! // #=> "Your project is: rusty-nail"
//! ```
@ -52,11 +52,11 @@
//! this returns only one result:
//!
//! ```
//! use names::Generator;
//! use names::{Generator, Name};
//!
//! let adjectives = &["imaginary"];
//! let nouns = &["roll"];
//! let mut generator = Generator::new(adjectives, nouns, Default::default());
//! let mut generator = Generator::new(adjectives, nouns, Name::default());
//!
//! assert_eq!("imaginary-roll", generator.next().unwrap());
//! ```
@ -65,8 +65,10 @@ extern crate rand;
use rand::Rng;
mod adjectives;
mod nouns;
pub const ADJECTIVES: &'static [&'static str] = &include!(concat!(env!("OUT_DIR"),
"/adjectives.rs"));
pub const NOUNS: &'static [&'static str] = &include!(concat!(env!("OUT_DIR"), "/nouns.rs"));
/// A naming strategy for the `Generator`
pub enum Name {
@ -78,7 +80,7 @@ pub enum Name {
}
impl Default for Name {
fn default() -> Name {
fn default() -> Self {
Name::Plain
}
}
@ -110,7 +112,7 @@ impl<'a> Generator<'a> {
///
/// assert_eq!("sassy-clocks", generator.next().unwrap());
/// ```
pub fn new(adjectives: &'a [&'a str], nouns: &'a [&'a str], naming: Name) -> Generator<'a> {
pub fn new(adjectives: &'a [&'a str], nouns: &'a [&'a str], naming: Name) -> Self {
Generator {
adjectives: adjectives,
nouns: nouns,
@ -128,8 +130,8 @@ impl<'a> Generator<'a> {
///
/// println!("My new name is: {}", generator.next().unwrap());
/// ```
pub fn with_naming(naming: Name) -> Generator<'a> {
Generator::new(adjectives::LIST, nouns::LIST, naming)
pub fn with_naming(naming: Name) -> Self {
Generator::new(ADJECTIVES, NOUNS, naming)
}
fn rand_adj(&self) -> &str {
@ -146,8 +148,8 @@ impl<'a> Generator<'a> {
}
impl<'a> Default for Generator<'a> {
fn default() -> Generator<'a> {
Generator::new(adjectives::LIST, nouns::LIST, Default::default())
fn default() -> Self {
Generator::new(ADJECTIVES, NOUNS, Name::default())
}
}

View File

@ -1,981 +0,0 @@
pub const LIST: &'static [&'static str] = &["able",
"account",
"achieve",
"achiever",
"acoustics",
"act",
"action",
"activity",
"actor",
"addition",
"adjustment",
"advertisement",
"advice",
"aftermath",
"afternoon",
"afterthought",
"agreement",
"air",
"airplane",
"airport",
"alarm",
"alley",
"amount",
"amusement",
"anger",
"angle",
"animal",
"answer",
"ant",
"ants",
"apparatus",
"apparel",
"apple",
"apples",
"appliance",
"approval",
"arch",
"argument",
"arithmetic",
"arm",
"army",
"art",
"attack",
"attempt",
"attention",
"attraction",
"aunt",
"authority",
"babies",
"baby",
"back",
"badge",
"bag",
"bait",
"balance",
"ball",
"balloon",
"balls",
"banana",
"band",
"base",
"baseball",
"basin",
"basket",
"basketball",
"bat",
"bath",
"battle",
"bead",
"beam",
"bean",
"bear",
"bears",
"beast",
"bed",
"bedroom",
"beds",
"bee",
"beef",
"beetle",
"beggar",
"beginner",
"behavior",
"belief",
"believe",
"bell",
"bells",
"berry",
"bike",
"bikes",
"bird",
"birds",
"birth",
"birthday",
"bit",
"bite",
"blade",
"blood",
"blow",
"board",
"boat",
"boats",
"body",
"bomb",
"bone",
"book",
"books",
"boot",
"border",
"bottle",
"boundary",
"box",
"boy",
"boys",
"brain",
"brake",
"branch",
"brass",
"bread",
"breakfast",
"breath",
"brick",
"bridge",
"brother",
"brothers",
"brush",
"bubble",
"bucket",
"building",
"bulb",
"bun",
"burn",
"burst",
"bushes",
"business",
"butter",
"button",
"cabbage",
"cable",
"cactus",
"cake",
"cakes",
"calculator",
"calendar",
"camera",
"camp",
"can",
"cannon",
"canvas",
"cap",
"caption",
"car",
"card",
"care",
"carpenter",
"carriage",
"cars",
"cart",
"cast",
"cat",
"cats",
"cattle",
"cause",
"cave",
"celery",
"cellar",
"cemetery",
"cent",
"chain",
"chair",
"chairs",
"chalk",
"chance",
"change",
"channel",
"cheese",
"cherries",
"cherry",
"chess",
"chicken",
"chickens",
"children",
"chin",
"church",
"circle",
"clam",
"class",
"clock",
"clocks",
"cloth",
"cloud",
"clouds",
"clover",
"club",
"coach",
"coal",
"coast",
"coat",
"cobweb",
"coil",
"collar",
"color",
"comb",
"comfort",
"committee",
"company",
"comparison",
"competition",
"condition",
"connection",
"control",
"cook",
"copper",
"copy",
"cord",
"cork",
"corn",
"cough",
"country",
"cover",
"cow",
"cows",
"crack",
"cracker",
"crate",
"crayon",
"cream",
"creator",
"creature",
"credit",
"crib",
"crime",
"crook",
"crow",
"crowd",
"crown",
"crush",
"cry",
"cub",
"cup",
"current",
"curtain",
"curve",
"cushion",
"dad",
"daughter",
"day",
"death",
"debt",
"decision",
"deer",
"degree",
"design",
"desire",
"desk",
"destruction",
"detail",
"development",
"digestion",
"dime",
"dinner",
"dinosaurs",
"direction",
"dirt",
"discovery",
"discussion",
"disease",
"disgust",
"distance",
"distribution",
"division",
"dock",
"doctor",
"dog",
"dogs",
"doll",
"dolls",
"donkey",
"door",
"downtown",
"drain",
"drawer",
"dress",
"drink",
"driving",
"drop",
"drug",
"drum",
"duck",
"ducks",
"dust",
"ear",
"earth",
"earthquake",
"edge",
"education",
"effect",
"egg",
"eggnog",
"eggs",
"elbow",
"end",
"engine",
"error",
"event",
"example",
"exchange",
"existence",
"expansion",
"experience",
"expert",
"eye",
"eyes",
"face",
"fact",
"fairies",
"fall",
"family",
"fan",
"fang",
"farm",
"farmer",
"father",
"faucet",
"fear",
"feast",
"feather",
"feeling",
"feet",
"fiction",
"field",
"fifth",
"fight",
"finger",
"fire",
"fireman",
"fish",
"flag",
"flame",
"flavor",
"flesh",
"flight",
"flock",
"floor",
"flower",
"flowers",
"fly",
"fog",
"fold",
"food",
"foot",
"force",
"fork",
"form",
"fowl",
"frame",
"friction",
"friend",
"friends",
"frog",
"frogs",
"front",
"fruit",
"fuel",
"furniture",
"galley",
"game",
"garden",
"gate",
"geese",
"ghost",
"giants",
"giraffe",
"girl",
"girls",
"glass",
"glove",
"glue",
"goat",
"gold",
"goldfish",
"good-bye",
"goose",
"government",
"governor",
"grade",
"grain",
"grandfather",
"grandmother",
"grape",
"grass",
"grip",
"ground",
"group",
"growth",
"guide",
"guitar",
"gun",
"hair",
"haircut",
"hall",
"hammer",
"hand",
"hands",
"harbor",
"harmony",
"hat",
"hate",
"head",
"health",
"hearing",
"heart",
"heat",
"help",
"hen",
"hill",
"history",
"hobbies",
"hole",
"holiday",
"home",
"honey",
"hook",
"hope",
"horn",
"horse",
"horses",
"hose",
"hospital",
"hot",
"hour",
"house",
"houses",
"humor",
"hydrant",
"ice",
"icicle",
"idea",
"impulse",
"income",
"increase",
"industry",
"ink",
"insect",
"instrument",
"insurance",
"interest",
"invention",
"iron",
"island",
"jail",
"jam",
"jar",
"jeans",
"jelly",
"jellyfish",
"jewel",
"join",
"joke",
"journey",
"judge",
"juice",
"jump",
"kettle",
"key",
"kick",
"kiss",
"kite",
"kitten",
"kittens",
"kitty",
"knee",
"knife",
"knot",
"knowledge",
"laborer",
"lace",
"ladybug",
"lake",
"lamp",
"land",
"language",
"laugh",
"lawyer",
"lead",
"leaf",
"learning",
"leather",
"leg",
"legs",
"letter",
"letters",
"lettuce",
"level",
"library",
"lift",
"light",
"limit",
"line",
"linen",
"lip",
"liquid",
"list",
"lizards",
"loaf",
"lock",
"locket",
"look",
"loss",
"love",
"low",
"lumber",
"lunch",
"lunchroom",
"machine",
"magic",
"maid",
"mailbox",
"man",
"manager",
"map",
"marble",
"mark",
"market",
"mask",
"mass",
"match",
"meal",
"measure",
"meat",
"meeting",
"memory",
"men",
"metal",
"mice",
"middle",
"milk",
"mind",
"mine",
"minister",
"mint",
"minute",
"mist",
"mitten",
"mom",
"money",
"monkey",
"month",
"moon",
"morning",
"mother",
"motion",
"mountain",
"mouth",
"move",
"muscle",
"music",
"nail",
"name",
"nation",
"neck",
"need",
"needle",
"nerve",
"nest",
"net",
"news",
"night",
"noise",
"north",
"nose",
"note",
"notebook",
"number",
"nut",
"oatmeal",
"observation",
"ocean",
"offer",
"office",
"oil",
"operation",
"opinion",
"orange",
"oranges",
"order",
"organization",
"ornament",
"oven",
"owl",
"owner",
"page",
"pail",
"pain",
"paint",
"pan",
"pancake",
"paper",
"parcel",
"parent",
"park",
"part",
"partner",
"party",
"passenger",
"paste",
"patch",
"payment",
"peace",
"pear",
"pen",
"pencil",
"person",
"pest",
"pet",
"pets",
"pickle",
"picture",
"pie",
"pies",
"pig",
"pigs",
"pin",
"pipe",
"pizzas",
"place",
"plane",
"planes",
"plant",
"plantation",
"plants",
"plastic",
"plate",
"play",
"playground",
"pleasure",
"plot",
"plough",
"pocket",
"point",
"poison",
"police",
"polish",
"pollution",
"popcorn",
"porter",
"position",
"pot",
"potato",
"powder",
"power",
"price",
"print",
"prison",
"process",
"produce",
"profit",
"property",
"prose",
"protest",
"pull",
"pump",
"punishment",
"purpose",
"push",
"quarter",
"quartz",
"queen",
"question",
"quicksand",
"quiet",
"quill",
"quilt",
"quince",
"quiver",
"rabbit",
"rabbits",
"rail",
"railway",
"rain",
"rainstorm",
"rake",
"range",
"rat",
"rate",
"ray",
"reaction",
"reading",
"reason",
"receipt",
"recess",
"record",
"regret",
"relation",
"religion",
"representative",
"request",
"respect",
"rest",
"reward",
"rhythm",
"rice",
"riddle",
"rifle",
"ring",
"rings",
"river",
"road",
"robin",
"rock",
"rod",
"roll",
"roof",
"room",
"root",
"rose",
"route",
"rub",
"rule",
"run",
"sack",
"sail",
"salt",
"sand",
"scale",
"scarecrow",
"scarf",
"scene",
"scent",
"school",
"science",
"scissors",
"screw",
"sea",
"seashore",
"seat",
"secretary",
"seed",
"selection",
"self",
"sense",
"servant",
"shade",
"shake",
"shame",
"shape",
"sheep",
"sheet",
"shelf",
"ship",
"shirt",
"shock",
"shoe",
"shoes",
"shop",
"show",
"side",
"sidewalk",
"sign",
"silk",
"silver",
"sink",
"sister",
"sisters",
"size",
"skate",
"skin",
"skirt",
"sky",
"slave",
"sleep",
"sleet",
"slip",
"slope",
"smash",
"smell",
"smile",
"smoke",
"snail",
"snails",
"snake",
"snakes",
"sneeze",
"snow",
"soap",
"society",
"sock",
"soda",
"sofa",
"son",
"song",
"songs",
"sort",
"sound",
"soup",
"space",
"spade",
"spark",
"spiders",
"sponge",
"spoon",
"spot",
"spring",
"spy",
"square",
"squirrel",
"stage",
"stamp",
"star",
"start",
"statement",
"station",
"steam",
"steel",
"stem",
"step",
"stew",
"stick",
"sticks",
"stitch",
"stocking",
"stomach",
"stone",
"stop",
"store",
"story",
"stove",
"stranger",
"straw",
"stream",
"street",
"stretch",
"string",
"structure",
"substance",
"sugar",
"suggestion",
"suit",
"summer",
"sun",
"support",
"surprise",
"sweater",
"swim",
"swing",
"system",
"table",
"tail",
"talk",
"tank",
"taste",
"tax",
"teaching",
"team",
"teeth",
"temper",
"tendency",
"tent",
"territory",
"test",
"texture",
"theory",
"thing",
"things",
"thought",
"thread",
"thrill",
"throat",
"throne",
"thumb",
"thunder",
"ticket",
"tiger",
"time",
"tin",
"title",
"toad",
"toe",
"toes",
"tomatoes",
"tongue",
"tooth",
"toothbrush",
"toothpaste",
"top",
"touch",
"town",
"toy",
"toys",
"trade",
"trail",
"train",
"trains",
"tramp",
"transport",
"tray",
"treatment",
"tree",
"trees",
"trick",
"trip",
"trouble",
"trousers",
"truck",
"trucks",
"tub",
"turkey",
"turn",
"twig",
"twist",
"umbrella",
"uncle",
"underwear",
"unit",
"use",
"vacation",
"value",
"van",
"vase",
"vegetable",
"veil",
"vein",
"verse",
"vessel",
"vest",
"view",
"visitor",
"voice",
"volcano",
"volleyball",
"voyage",
"walk",
"wall",
"war",
"wash",
"waste",
"watch",
"water",
"wave",
"waves",
"wax",
"way",
"wealth",
"weather",
"week",
"weight",
"wheel",
"whip",
"whistle",
"wilderness",
"wind",
"window",
"wine",
"wing",
"winter",
"wire",
"wish",
"woman",
"women",
"wood",
"wool",
"word",
"work",
"worm",
"wound",
"wren",
"wrench",
"wrist",
"writer",
"writing",
"yak",
"yam",
"yard",
"yarn",
"year",
"yoke",
"zebra",
"zephyr",
"zinc",
"zipper",
"zoo"];