Add old lady who swalled a fly example

This commit is contained in:
Timothy Warren 2019-02-12 12:35:49 -05:00
parent c5a08e2226
commit 396dde530e
5 changed files with 170 additions and 77 deletions

View File

@ -44,6 +44,7 @@
<cargoProject FILE="$PROJECT_DIR$/macros/Cargo.toml" /> <cargoProject FILE="$PROJECT_DIR$/macros/Cargo.toml" />
<cargoProject FILE="$PROJECT_DIR$/pancakes/Cargo.toml" /> <cargoProject FILE="$PROJECT_DIR$/pancakes/Cargo.toml" />
<cargoProject FILE="$PROJECT_DIR$/hello/Cargo.toml" /> <cargoProject FILE="$PROJECT_DIR$/hello/Cargo.toml" />
<cargoProject FILE="$PROJECT_DIR$/old_lady_who_swallowed_a_fly/Cargo.toml" />
</component> </component>
<component name="ComposerJsonPluginSettings"> <component name="ComposerJsonPluginSettings">
<unboundedVersionInspectionSettings> <unboundedVersionInspectionSettings>

View File

@ -177,6 +177,10 @@
<sourceFolder url="file://$MODULE_DIR$/hello/examples" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/hello/examples" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/hello/tests" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/hello/tests" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/hello/benches" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/hello/benches" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/old_lady_who_swallowed_a_fly/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/old_lady_who_swallowed_a_fly/examples" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/old_lady_who_swallowed_a_fly/tests" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/old_lady_who_swallowed_a_fly/benches" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/add/add-one/target" /> <excludeFolder url="file://$MODULE_DIR$/add/add-one/target" />
<excludeFolder url="file://$MODULE_DIR$/add/adder/target" /> <excludeFolder url="file://$MODULE_DIR$/add/adder/target" />
<excludeFolder url="file://$MODULE_DIR$/adder/target" /> <excludeFolder url="file://$MODULE_DIR$/adder/target" />
@ -204,6 +208,7 @@
<excludeFolder url="file://$MODULE_DIR$/minigrep_v2/target" /> <excludeFolder url="file://$MODULE_DIR$/minigrep_v2/target" />
<excludeFolder url="file://$MODULE_DIR$/modules/target" /> <excludeFolder url="file://$MODULE_DIR$/modules/target" />
<excludeFolder url="file://$MODULE_DIR$/mutex/target" /> <excludeFolder url="file://$MODULE_DIR$/mutex/target" />
<excludeFolder url="file://$MODULE_DIR$/old_lady_who_swallowed_a_fly/target" />
<excludeFolder url="file://$MODULE_DIR$/oop/target" /> <excludeFolder url="file://$MODULE_DIR$/oop/target" />
<excludeFolder url="file://$MODULE_DIR$/pancakes/target" /> <excludeFolder url="file://$MODULE_DIR$/pancakes/target" />
<excludeFolder url="file://$MODULE_DIR$/pattern_matching/target" /> <excludeFolder url="file://$MODULE_DIR$/pattern_matching/target" />

View File

@ -15,23 +15,28 @@
<component name="FileEditorManager"> <component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300"> <leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="true"> <file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/hello/src/bin/main.rs"> <entry file="file://$PROJECT_DIR$/old_lady_who_swallowed_a_fly/src/main.rs">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="336"> <state relative-caret-position="768">
<caret line="21" column="31" selection-start-line="21" selection-start-column="31" selection-end-line="21" selection-end-column="31" /> <caret line="48" column="10" lean-forward="true" selection-start-line="48" selection-start-column="10" selection-end-line="48" selection-end-column="10" />
</state> </state>
</provider> </provider>
</entry> </entry>
</file> </file>
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/hello/src/lib.rs"> <entry file="file://$PROJECT_DIR$/loops/src/main.rs">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1183"> <state relative-caret-position="944">
<caret line="83" lean-forward="true" selection-start-line="83" selection-end-line="83" /> <caret line="59" selection-start-line="59" selection-end-line="59" />
<folding> </state>
<element signature="e#194#195#0" expanded="true" /> </provider>
<element signature="e#211#212#0" expanded="true" /> </entry>
</folding> </file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/twelve_days_of_christmas/src/main.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="752">
<caret line="47" selection-start-line="47" selection-end-line="47" />
</state> </state>
</provider> </provider>
</entry> </entry>
@ -65,7 +70,6 @@
<component name="IdeDocumentHistory"> <component name="IdeDocumentHistory">
<option name="CHANGED_PATHS"> <option name="CHANGED_PATHS">
<list> <list>
<option value="$PROJECT_DIR$/minigrep/src/lib.rs" />
<option value="$PROJECT_DIR$/minigrep/src/main.rs" /> <option value="$PROJECT_DIR$/minigrep/src/main.rs" />
<option value="$PROJECT_DIR$/closures/src/main.rs" /> <option value="$PROJECT_DIR$/closures/src/main.rs" />
<option value="$PROJECT_DIR$/closures/src/lib.rs" /> <option value="$PROJECT_DIR$/closures/src/lib.rs" />
@ -116,6 +120,7 @@
<option value="$PROJECT_DIR$/hello/bin/main.rs" /> <option value="$PROJECT_DIR$/hello/bin/main.rs" />
<option value="$PROJECT_DIR$/hello/src/lib.rs" /> <option value="$PROJECT_DIR$/hello/src/lib.rs" />
<option value="$PROJECT_DIR$/hello/src/bin/main.rs" /> <option value="$PROJECT_DIR$/hello/src/bin/main.rs" />
<option value="$PROJECT_DIR$/old_lady_who_swallowed_a_fly/src/main.rs" />
</list> </list>
</option> </option>
</component> </component>
@ -126,10 +131,10 @@
<other-services-enabled>false</other-services-enabled> <other-services-enabled>false</other-services-enabled>
</component> </component>
<component name="ProjectFrameBounds" extendedState="6"> <component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="1920" /> <option name="x" value="1680" />
<option name="y" value="-438" /> <option name="y" value="370" />
<option name="width" value="1080" /> <option name="width" value="1050" />
<option name="height" value="1897" /> <option name="height" value="877" />
</component> </component>
<component name="ProjectLevelVcsManager" settingsEditedManually="true"> <component name="ProjectLevelVcsManager" settingsEditedManually="true">
<ConfirmationsSetting value="1" id="Add" /> <ConfirmationsSetting value="1" id="Add" />
@ -172,18 +177,35 @@
<path> <path>
<item name="rust" type="3d21c010:ScopeViewTreeModel$ProjectNode" /> <item name="rust" type="3d21c010:ScopeViewTreeModel$ProjectNode" />
<item name="rust" type="2674bda8:ScopeViewTreeModel$GroupNode" /> <item name="rust" type="2674bda8:ScopeViewTreeModel$GroupNode" />
<item name="hello" type="9f88c78c:ScopeViewTreeModel$FileNode" /> <item name="loops" type="9f88c78c:ScopeViewTreeModel$FileNode" />
</path> </path>
<path> <path>
<item name="rust" type="3d21c010:ScopeViewTreeModel$ProjectNode" /> <item name="rust" type="3d21c010:ScopeViewTreeModel$ProjectNode" />
<item name="rust" type="2674bda8:ScopeViewTreeModel$GroupNode" /> <item name="rust" type="2674bda8:ScopeViewTreeModel$GroupNode" />
<item name="hello" type="9f88c78c:ScopeViewTreeModel$FileNode" /> <item name="loops" type="9f88c78c:ScopeViewTreeModel$FileNode" />
<item name="src" type="9f88c78c:ScopeViewTreeModel$FileNode" /> <item name="src" type="9f88c78c:ScopeViewTreeModel$FileNode" />
</path> </path>
<path> <path>
<item name="rust" type="3d21c010:ScopeViewTreeModel$ProjectNode" /> <item name="rust" type="3d21c010:ScopeViewTreeModel$ProjectNode" />
<item name="rust" type="2674bda8:ScopeViewTreeModel$GroupNode" /> <item name="rust" type="2674bda8:ScopeViewTreeModel$GroupNode" />
<item name="pancakes" type="9f88c78c:ScopeViewTreeModel$FileNode" /> <item name="old_lady_who_swallowed_a_fly" type="9f88c78c:ScopeViewTreeModel$FileNode" />
</path>
<path>
<item name="rust" type="3d21c010:ScopeViewTreeModel$ProjectNode" />
<item name="rust" type="2674bda8:ScopeViewTreeModel$GroupNode" />
<item name="old_lady_who_swallowed_a_fly" type="9f88c78c:ScopeViewTreeModel$FileNode" />
<item name="src" type="9f88c78c:ScopeViewTreeModel$FileNode" />
</path>
<path>
<item name="rust" type="3d21c010:ScopeViewTreeModel$ProjectNode" />
<item name="rust" type="2674bda8:ScopeViewTreeModel$GroupNode" />
<item name="twelve_days_of_christmas" type="9f88c78c:ScopeViewTreeModel$FileNode" />
</path>
<path>
<item name="rust" type="3d21c010:ScopeViewTreeModel$ProjectNode" />
<item name="rust" type="2674bda8:ScopeViewTreeModel$GroupNode" />
<item name="twelve_days_of_christmas" type="9f88c78c:ScopeViewTreeModel$FileNode" />
<item name="src" type="9f88c78c:ScopeViewTreeModel$FileNode" />
</path> </path>
</expand> </expand>
<select /> <select />
@ -193,7 +215,7 @@
</component> </component>
<component name="PropertiesComponent"> <component name="PropertiesComponent">
<property name="JavaScriptWeakerCompletionTypeGuess" value="true" /> <property name="JavaScriptWeakerCompletionTypeGuess" value="true" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1549907921290" /> <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1549991319219" />
<property name="javascript.nodejs.core.library.configured.version" value="7.1.0" /> <property name="javascript.nodejs.core.library.configured.version" value="7.1.0" />
<property name="js.eslint.eslintPackage" value="$USER_HOME$/.yarn-config/global/node_modules/.bin/eslint" /> <property name="js.eslint.eslintPackage" value="$USER_HOME$/.yarn-config/global/node_modules/.bin/eslint" />
<property name="js.eslint.nodeInterpreter" value="project" /> <property name="js.eslint.nodeInterpreter" value="project" />
@ -227,7 +249,7 @@
</list> </list>
</option> </option>
</component> </component>
<component name="RunManager" selected="Cargo Command.Run hello"> <component name="RunManager" selected="Cargo Command.Run old_lady_who_swallowed_a_fly">
<configuration name="&lt;template&gt;" type="TestNG" default="true" selected="false"> <configuration name="&lt;template&gt;" type="TestNG" default="true" selected="false">
<option name="MAIN_CLASS_NAME" /> <option name="MAIN_CLASS_NAME" />
<option name="VM_PARAMETERS" value="-ea" /> <option name="VM_PARAMETERS" value="-ea" />
@ -256,16 +278,6 @@
<envs /> <envs />
<method v="2" /> <method v="2" />
</configuration> </configuration>
<configuration name="Run advanced_traits" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
<option name="channel" value="DEFAULT" />
<option name="command" value="run --package advanced_traits --bin advanced_traits" />
<option name="allFeatures" value="false" />
<option name="nocapture" value="false" />
<option name="backtrace" value="SHORT" />
<option name="workingDirectory" value="file://$PROJECT_DIR$/advanced_traits" />
<envs />
<method v="2" />
</configuration>
<configuration name="Run advanced_types" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true"> <configuration name="Run advanced_types" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
<option name="channel" value="DEFAULT" /> <option name="channel" value="DEFAULT" />
<option name="command" value="run --package advanced_types --bin advanced_types" /> <option name="command" value="run --package advanced_types --bin advanced_types" />
@ -286,6 +298,16 @@
<envs /> <envs />
<method v="2" /> <method v="2" />
</configuration> </configuration>
<configuration name="Run old_lady_who_swallowed_a_fly" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
<option name="channel" value="DEFAULT" />
<option name="command" value="run --package old_lady_who_swallowed_a_fly --bin old_lady_who_swallowed_a_fly" />
<option name="allFeatures" value="false" />
<option name="nocapture" value="false" />
<option name="backtrace" value="SHORT" />
<option name="workingDirectory" value="file://$PROJECT_DIR$/old_lady_who_swallowed_a_fly" />
<envs />
<method v="2" />
</configuration>
<configuration name="Run pancakes" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true"> <configuration name="Run pancakes" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
<option name="channel" value="DEFAULT" /> <option name="channel" value="DEFAULT" />
<option name="command" value="run --package pancakes --bin pancakes" /> <option name="command" value="run --package pancakes --bin pancakes" />
@ -305,11 +327,11 @@
</configuration> </configuration>
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="Cargo Command.Run old_lady_who_swallowed_a_fly" />
<item itemvalue="Cargo Command.Run hello" /> <item itemvalue="Cargo Command.Run hello" />
<item itemvalue="Cargo Command.Run pancakes" /> <item itemvalue="Cargo Command.Run pancakes" />
<item itemvalue="Cargo Command.Run advanced_functions" /> <item itemvalue="Cargo Command.Run advanced_functions" />
<item itemvalue="Cargo Command.Run advanced_types" /> <item itemvalue="Cargo Command.Run advanced_types" />
<item itemvalue="Cargo Command.Run advanced_traits" />
</list> </list>
</recent_temporary> </recent_temporary>
</component> </component>
@ -346,11 +368,11 @@
</history-entry> </history-entry>
</component> </component>
<component name="ToolWindowManager"> <component name="ToolWindowManager">
<frame x="1920" y="-438" width="1080" height="1897" extended-state="6" /> <frame x="1680" y="-410" width="1050" height="1657" extended-state="6" />
<editor active="true" /> <editor active="true" />
<layout> <layout>
<window_info content_ui="combo" id="Project" order="0" sideWeight="0.4957483" visible="true" weight="0.2540132" /> <window_info content_ui="combo" id="Project" order="0" sideWeight="0.49522156" visible="true" weight="0.26141885" />
<window_info id="Structure" order="1" sideWeight="0.5042517" side_tool="true" visible="true" weight="0.2540132" /> <window_info id="Structure" order="1" sideWeight="0.50477844" side_tool="true" visible="true" weight="0.26141885" />
<window_info id="Image Layers" order="2" /> <window_info id="Image Layers" order="2" />
<window_info id="Designer" order="3" /> <window_info id="Designer" order="3" />
<window_info id="Capture Tool" order="4" /> <window_info id="Capture Tool" order="4" />
@ -358,7 +380,7 @@
<window_info id="Cargo" order="6" sideWeight="0.49791494" weight="0.3286119" /> <window_info id="Cargo" order="6" sideWeight="0.49791494" weight="0.3286119" />
<window_info anchor="bottom" id="Message" order="0" /> <window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" weight="0.32979318" /> <window_info anchor="bottom" id="Find" order="1" weight="0.32979318" />
<window_info anchor="bottom" id="Run" order="2" weight="0.2571269" /> <window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.25693995" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" /> <window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" /> <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" /> <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
@ -366,7 +388,7 @@
<window_info anchor="bottom" id="Docker" order="7" show_stripe_button="false" /> <window_info anchor="bottom" id="Docker" order="7" show_stripe_button="false" />
<window_info anchor="bottom" id="Version Control" order="8" /> <window_info anchor="bottom" id="Version Control" order="8" />
<window_info anchor="bottom" id="Inspection Results" order="9" weight="0.32979318" /> <window_info anchor="bottom" id="Inspection Results" order="9" weight="0.32979318" />
<window_info active="true" anchor="bottom" id="Terminal" order="10" visible="true" weight="0.34264952" /> <window_info anchor="bottom" id="Terminal" order="10" weight="0.34264952" />
<window_info anchor="bottom" id="Event Log" order="11" side_tool="true" /> <window_info anchor="bottom" id="Event Log" order="11" side_tool="true" />
<window_info anchor="right" id="Commander" order="0" weight="0.4" /> <window_info anchor="right" id="Commander" order="0" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" /> <window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
@ -380,36 +402,6 @@
<option name="version" value="1" /> <option name="version" value="1" />
</component> </component>
<component name="editorHistoryManager"> <component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/adder/tests/integration_test.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="144">
<caret line="9" lean-forward="true" selection-start-line="9" selection-end-line="9" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/adder/src/lib.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1056">
<caret line="66" column="5" selection-start-line="66" selection-start-column="5" selection-end-line="66" selection-end-column="5" />
<folding>
<element signature="e#251#252#0" expanded="true" />
<element signature="e#263#264#0" expanded="true" />
<element signature="e#304#305#0" expanded="true" />
<element signature="e#338#339#0" expanded="true" />
<element signature="e#1036#1037#0" expanded="true" />
<element signature="e#1077#1078#0" expanded="true" />
<element signature="e#1119#1120#0" expanded="true" />
<element signature="e#1160#1161#0" expanded="true" />
<element signature="e#1196#1197#0" expanded="true" />
<element signature="e#1241#1242#0" expanded="true" />
<element signature="e#1191#1192#0" expanded="true" />
<element signature="e#1232#1233#0" expanded="true" />
<element signature="e#1520#1521#0" expanded="true" />
<element signature="e#1551#1552#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/minigrep/poem.txt"> <entry file="file://$PROJECT_DIR$/minigrep/poem.txt">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="128"> <state relative-caret-position="128">
@ -587,13 +579,6 @@
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/twelve_days_of_christmas/src/main.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="144">
<caret line="9" column="25" selection-start-line="9" selection-start-column="25" selection-end-line="9" selection-end-column="25" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/gui/src/main.rs"> <entry file="file://$PROJECT_DIR$/gui/src/main.rs">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="576"> <state relative-caret-position="576">
@ -802,8 +787,8 @@
</entry> </entry>
<entry file="file://$PROJECT_DIR$/hello/src/lib.rs"> <entry file="file://$PROJECT_DIR$/hello/src/lib.rs">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1183"> <state relative-caret-position="400">
<caret line="83" lean-forward="true" selection-start-line="83" selection-end-line="83" /> <caret line="25" column="39" selection-start-line="25" selection-start-column="39" selection-end-line="25" selection-end-column="39" />
<folding> <folding>
<element signature="e#194#195#0" expanded="true" /> <element signature="e#194#195#0" expanded="true" />
<element signature="e#211#212#0" expanded="true" /> <element signature="e#211#212#0" expanded="true" />
@ -813,8 +798,29 @@
</entry> </entry>
<entry file="file://$PROJECT_DIR$/hello/src/bin/main.rs"> <entry file="file://$PROJECT_DIR$/hello/src/bin/main.rs">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="336"> <state relative-caret-position="768">
<caret line="21" column="31" selection-start-line="21" selection-start-column="31" selection-end-line="21" selection-end-column="31" /> <caret line="48" selection-start-line="48" selection-end-line="48" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/twelve_days_of_christmas/src/main.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="752">
<caret line="47" selection-start-line="47" selection-end-line="47" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/loops/src/main.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="944">
<caret line="59" selection-start-line="59" selection-end-line="59" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/old_lady_who_swallowed_a_fly/src/main.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="768">
<caret line="48" column="10" lean-forward="true" selection-start-line="48" selection-start-column="10" selection-end-line="48" selection-end-column="10" />
</state> </state>
</provider> </provider>
</entry> </entry>

View File

@ -0,0 +1,7 @@
[package]
name = "old_lady_who_swallowed_a_fly"
version = "0.1.0"
authors = ["Timothy Warren <twarren@nabancard.com>"]
edition = "2018"
[dependencies]

View File

@ -0,0 +1,74 @@
#[derive(Clone, Debug)]
enum Flow { Every, Once, End }
use Flow::*;
#[derive(Clone, Debug)]
struct Verse {
animal: String,
flow_type: Flow,
aside: String,
}
impl Verse {
pub fn new(animal: &str, flow_type: Flow, aside: &str) -> Verse {
Verse {
animal: String::from(animal),
flow_type,
aside: String::from(aside)
}
}
}
fn swallowed_a(verse: &Verse) {
println!("\nThere was an old lady who swallowed a {};\n{}", verse.animal, verse.aside);
}
fn cumulative_refrain(slice: &[Verse]) {
for n in 0..slice.len() {
let repeat = &slice[n];
if n != (slice.len() - 1) {
let prev = &slice[n + 1];
println!("\tShe swallowed the {} to catch the {};", repeat.animal, prev.animal);
if let Every = prev.flow_type {
println!("\t{}", prev.aside);
}
}
}
}
fn print_verses(animals: [Verse;8]) {
for index in 0..animals.len() {
let verse = &animals[index];
swallowed_a(&verse);
// End early on the last verse
if let End = verse.flow_type {
return
};
if index > 0 {
let slice = &animals[0..=index];
let mut slice = slice.to_vec();
slice.reverse();
cumulative_refrain(&slice);
}
}
}
fn main() {
let animals = [
Verse::new("fly", Every, "I don't know why she swallowed a fly - perhaps she'll die!"),
Verse::new("spider", Every, "That wriggled and jiggled and tickled inside her!"),
Verse::new("bird", Once, "How absurd to swallow a bird!"),
Verse::new("cat", Once, "Imagine that! She swallowed a cat!"),
Verse::new("dog", Once, "What a hog, to swallow a dog!"),
Verse::new("goat", Once, "She just opened her throat and swallowed a goat!"),
Verse::new("cow", Once, "I don't know how she swallowed a cow!"),
Verse::new("horse", End, "She's dead of course!"),
];
print_verses(animals);
}