Add first iteration of blog example
This commit is contained in:
parent
bac5c02bd8
commit
48e6aba776
1
.idea/misc.xml
generated
1
.idea/misc.xml
generated
@ -34,6 +34,7 @@
|
|||||||
<cargoProject FILE="$PROJECT_DIR$/twelve_days_of_christmas/Cargo.toml" />
|
<cargoProject FILE="$PROJECT_DIR$/twelve_days_of_christmas/Cargo.toml" />
|
||||||
<cargoProject FILE="$PROJECT_DIR$/trait_objects/Cargo.toml" />
|
<cargoProject FILE="$PROJECT_DIR$/trait_objects/Cargo.toml" />
|
||||||
<cargoProject FILE="$PROJECT_DIR$/gui/Cargo.toml" />
|
<cargoProject FILE="$PROJECT_DIR$/gui/Cargo.toml" />
|
||||||
|
<cargoProject FILE="$PROJECT_DIR$/blog/Cargo.toml" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ComposerJsonPluginSettings">
|
<component name="ComposerJsonPluginSettings">
|
||||||
<unboundedVersionInspectionSettings>
|
<unboundedVersionInspectionSettings>
|
||||||
|
5
.idea/rust.iml
generated
5
.idea/rust.iml
generated
@ -137,9 +137,14 @@
|
|||||||
<sourceFolder url="file://$MODULE_DIR$/gui/examples" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/gui/examples" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/gui/tests" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/gui/tests" isTestSource="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/gui/benches" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/gui/benches" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/blog/src" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/blog/examples" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/blog/tests" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/blog/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" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/blog/target" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/branches/target" />
|
<excludeFolder url="file://$MODULE_DIR$/branches/target" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/closures/target" />
|
<excludeFolder url="file://$MODULE_DIR$/closures/target" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/ctof/target" />
|
<excludeFolder url="file://$MODULE_DIR$/ctof/target" />
|
||||||
|
147
.idea/workspace.xml
generated
147
.idea/workspace.xml
generated
@ -13,7 +13,48 @@
|
|||||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="FileEditorManager">
|
<component name="FileEditorManager">
|
||||||
<leaf />
|
<leaf>
|
||||||
|
<file pinned="false" current-in-tab="true">
|
||||||
|
<entry file="file://$PROJECT_DIR$/blog/src/main.rs">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state relative-caret-position="224">
|
||||||
|
<caret line="14" lean-forward="true" selection-start-line="14" selection-end-line="14" />
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
</file>
|
||||||
|
<file pinned="false" current-in-tab="false">
|
||||||
|
<entry file="file://$PROJECT_DIR$/blog/src/lib.rs">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state relative-caret-position="624">
|
||||||
|
<caret line="39" column="5" lean-forward="true" selection-start-line="39" selection-start-column="5" selection-end-line="39" selection-end-column="5" />
|
||||||
|
<folding>
|
||||||
|
<element signature="e#276#277#0" expanded="true" />
|
||||||
|
<element signature="e#303#304#0" expanded="true" />
|
||||||
|
<element signature="e#352#353#0" expanded="true" />
|
||||||
|
<element signature="e#377#378#0" expanded="true" />
|
||||||
|
<element signature="e#879#880#0" expanded="true" />
|
||||||
|
<element signature="e#896#897#0" expanded="true" />
|
||||||
|
<element signature="e#701#702#0" expanded="true" />
|
||||||
|
<element signature="e#726#727#0" expanded="true" />
|
||||||
|
<element signature="e#983#984#0" expanded="true" />
|
||||||
|
<element signature="e#1002#1003#0" expanded="true" />
|
||||||
|
<element signature="e#856#857#0" expanded="true" />
|
||||||
|
<element signature="e#875#876#0" expanded="true" />
|
||||||
|
<element signature="e#1196#1197#0" expanded="true" />
|
||||||
|
<element signature="e#1221#1222#0" expanded="true" />
|
||||||
|
<element signature="e#1347#1348#0" expanded="true" />
|
||||||
|
<element signature="e#1366#1367#0" expanded="true" />
|
||||||
|
<element signature="e#1423#1424#0" expanded="true" />
|
||||||
|
<element signature="e#1442#1443#0" expanded="true" />
|
||||||
|
<element signature="e#1599#1600#0" expanded="true" />
|
||||||
|
<element signature="e#1615#1616#0" expanded="true" />
|
||||||
|
</folding>
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
</file>
|
||||||
|
</leaf>
|
||||||
</component>
|
</component>
|
||||||
<component name="FileTemplateManagerImpl">
|
<component name="FileTemplateManagerImpl">
|
||||||
<option name="RECENT_TEMPLATES">
|
<option name="RECENT_TEMPLATES">
|
||||||
@ -42,8 +83,6 @@
|
|||||||
<component name="IdeDocumentHistory">
|
<component name="IdeDocumentHistory">
|
||||||
<option name="CHANGED_PATHS">
|
<option name="CHANGED_PATHS">
|
||||||
<list>
|
<list>
|
||||||
<option value="$PROJECT_DIR$/scope/src/main.rs" />
|
|
||||||
<option value="$PROJECT_DIR$/references/src/main.rs" />
|
|
||||||
<option value="$PROJECT_DIR$/slices/src/main.rs" />
|
<option value="$PROJECT_DIR$/slices/src/main.rs" />
|
||||||
<option value="$PROJECT_DIR$/structs/src/main.rs" />
|
<option value="$PROJECT_DIR$/structs/src/main.rs" />
|
||||||
<option value="$PROJECT_DIR$/rectangles/src/main.rs" />
|
<option value="$PROJECT_DIR$/rectangles/src/main.rs" />
|
||||||
@ -93,6 +132,8 @@
|
|||||||
<option value="$PROJECT_DIR$/trait_objects/Cargo.toml" />
|
<option value="$PROJECT_DIR$/trait_objects/Cargo.toml" />
|
||||||
<option value="$PROJECT_DIR$/gui/src/main.rs" />
|
<option value="$PROJECT_DIR$/gui/src/main.rs" />
|
||||||
<option value="$PROJECT_DIR$/gui/src/lib.rs" />
|
<option value="$PROJECT_DIR$/gui/src/lib.rs" />
|
||||||
|
<option value="$PROJECT_DIR$/blog/src/main.rs" />
|
||||||
|
<option value="$PROJECT_DIR$/blog/src/lib.rs" />
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
@ -123,6 +164,17 @@
|
|||||||
<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" />
|
||||||
</path>
|
</path>
|
||||||
|
<path>
|
||||||
|
<item name="rust" type="3d21c010:ScopeViewTreeModel$ProjectNode" />
|
||||||
|
<item name="rust" type="2674bda8:ScopeViewTreeModel$GroupNode" />
|
||||||
|
<item name="blog" type="9f88c78c:ScopeViewTreeModel$FileNode" />
|
||||||
|
</path>
|
||||||
|
<path>
|
||||||
|
<item name="rust" type="3d21c010:ScopeViewTreeModel$ProjectNode" />
|
||||||
|
<item name="rust" type="2674bda8:ScopeViewTreeModel$GroupNode" />
|
||||||
|
<item name="blog" type="9f88c78c:ScopeViewTreeModel$FileNode" />
|
||||||
|
<item name="src" type="9f88c78c:ScopeViewTreeModel$FileNode" />
|
||||||
|
</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" />
|
||||||
@ -165,7 +217,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="1549480480153" />
|
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1549482664512" />
|
||||||
<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" />
|
||||||
@ -193,7 +245,7 @@
|
|||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
<component name="RunManager" selected="Cargo Command.Run gui">
|
<component name="RunManager" selected="Cargo Command.Run blog">
|
||||||
<configuration name="<template>" type="TestNG" default="true" selected="false">
|
<configuration name="<template>" 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" />
|
||||||
@ -212,6 +264,16 @@
|
|||||||
<option name="Make" enabled="true" />
|
<option name="Make" enabled="true" />
|
||||||
</method>
|
</method>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
<configuration name="Run blog" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
|
||||||
|
<option name="channel" value="DEFAULT" />
|
||||||
|
<option name="command" value="run --package blog --bin blog" />
|
||||||
|
<option name="allFeatures" value="false" />
|
||||||
|
<option name="nocapture" value="false" />
|
||||||
|
<option name="backtrace" value="SHORT" />
|
||||||
|
<option name="workingDirectory" value="file://$PROJECT_DIR$/blog" />
|
||||||
|
<envs />
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
<configuration name="Run gui" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
|
<configuration name="Run gui" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
|
||||||
<option name="channel" value="DEFAULT" />
|
<option name="channel" value="DEFAULT" />
|
||||||
<option name="command" value="run --package gui --bin gui" />
|
<option name="command" value="run --package gui --bin gui" />
|
||||||
@ -232,16 +294,6 @@
|
|||||||
<envs />
|
<envs />
|
||||||
<method v="2" />
|
<method v="2" />
|
||||||
</configuration>
|
</configuration>
|
||||||
<configuration name="Run threads" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
|
|
||||||
<option name="channel" value="DEFAULT" />
|
|
||||||
<option name="command" value="run --package threads --bin threads" />
|
|
||||||
<option name="allFeatures" value="false" />
|
|
||||||
<option name="nocapture" value="false" />
|
|
||||||
<option name="backtrace" value="SHORT" />
|
|
||||||
<option name="workingDirectory" value="file://$PROJECT_DIR$/threads" />
|
|
||||||
<envs />
|
|
||||||
<method v="2" />
|
|
||||||
</configuration>
|
|
||||||
<configuration name="Run twelve_days_of_christmas" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
|
<configuration name="Run twelve_days_of_christmas" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
|
||||||
<option name="channel" value="DEFAULT" />
|
<option name="channel" value="DEFAULT" />
|
||||||
<option name="command" value="run --package twelve_days_of_christmas --bin twelve_days_of_christmas" />
|
<option name="command" value="run --package twelve_days_of_christmas --bin twelve_days_of_christmas" />
|
||||||
@ -271,11 +323,11 @@
|
|||||||
</configuration>
|
</configuration>
|
||||||
<recent_temporary>
|
<recent_temporary>
|
||||||
<list>
|
<list>
|
||||||
|
<item itemvalue="Cargo Command.Run blog" />
|
||||||
<item itemvalue="Cargo Command.Run gui" />
|
<item itemvalue="Cargo Command.Run gui" />
|
||||||
<item itemvalue="Cargo Command.Test lib::tests" />
|
<item itemvalue="Cargo Command.Test lib::tests" />
|
||||||
<item itemvalue="Cargo Command.Run twelve_days_of_christmas" />
|
<item itemvalue="Cargo Command.Run twelve_days_of_christmas" />
|
||||||
<item itemvalue="Cargo Command.Run mutex" />
|
<item itemvalue="Cargo Command.Run mutex" />
|
||||||
<item itemvalue="Cargo Command.Run threads" />
|
|
||||||
</list>
|
</list>
|
||||||
</recent_temporary>
|
</recent_temporary>
|
||||||
</component>
|
</component>
|
||||||
@ -313,9 +365,10 @@
|
|||||||
</component>
|
</component>
|
||||||
<component name="ToolWindowManager">
|
<component name="ToolWindowManager">
|
||||||
<frame x="1680" y="-410" width="1050" height="1657" extended-state="6" />
|
<frame x="1680" y="-410" width="1050" height="1657" extended-state="6" />
|
||||||
|
<editor active="true" />
|
||||||
<layout>
|
<layout>
|
||||||
<window_info active="true" content_ui="combo" id="Project" order="0" sideWeight="0.4960707" visible="true" weight="0.26141885" />
|
<window_info content_ui="combo" id="Project" order="0" sideWeight="0.49586776" visible="true" weight="0.26141885" />
|
||||||
<window_info id="Structure" order="1" sideWeight="0.50392926" side_tool="true" visible="true" weight="0.26141885" />
|
<window_info id="Structure" order="1" sideWeight="0.5041322" 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" />
|
||||||
@ -323,7 +376,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.29696578" />
|
<window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.29696578" />
|
||||||
<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" />
|
||||||
@ -331,7 +384,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 anchor="bottom" id="Terminal" order="10" visible="true" weight="0.3428018" />
|
<window_info anchor="bottom" id="Terminal" order="10" weight="0.3428018" />
|
||||||
<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" />
|
||||||
@ -345,24 +398,6 @@
|
|||||||
<option name="version" value="1" />
|
<option name="version" value="1" />
|
||||||
</component>
|
</component>
|
||||||
<component name="editorHistoryManager">
|
<component name="editorHistoryManager">
|
||||||
<entry file="file://$PROJECT_DIR$/ftoc/src/main.rs">
|
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
|
||||||
<state relative-caret-position="352">
|
|
||||||
<caret line="22" lean-forward="true" selection-start-line="22" selection-end-line="22" />
|
|
||||||
<folding>
|
|
||||||
<element signature="e#456#457#0" expanded="true" />
|
|
||||||
<element signature="e#488#489#0" expanded="true" />
|
|
||||||
</folding>
|
|
||||||
</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" lean-forward="true" selection-start-line="59" selection-end-line="59" />
|
|
||||||
</state>
|
|
||||||
</provider>
|
|
||||||
</entry>
|
|
||||||
<entry file="file://$PROJECT_DIR$/references/src/main.rs">
|
<entry file="file://$PROJECT_DIR$/references/src/main.rs">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state relative-caret-position="368">
|
<state relative-caret-position="368">
|
||||||
@ -785,5 +820,41 @@
|
|||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
|
<entry file="file://$PROJECT_DIR$/blog/src/lib.rs">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state relative-caret-position="624">
|
||||||
|
<caret line="39" column="5" lean-forward="true" selection-start-line="39" selection-start-column="5" selection-end-line="39" selection-end-column="5" />
|
||||||
|
<folding>
|
||||||
|
<element signature="e#276#277#0" expanded="true" />
|
||||||
|
<element signature="e#303#304#0" expanded="true" />
|
||||||
|
<element signature="e#352#353#0" expanded="true" />
|
||||||
|
<element signature="e#377#378#0" expanded="true" />
|
||||||
|
<element signature="e#879#880#0" expanded="true" />
|
||||||
|
<element signature="e#896#897#0" expanded="true" />
|
||||||
|
<element signature="e#701#702#0" expanded="true" />
|
||||||
|
<element signature="e#726#727#0" expanded="true" />
|
||||||
|
<element signature="e#983#984#0" expanded="true" />
|
||||||
|
<element signature="e#1002#1003#0" expanded="true" />
|
||||||
|
<element signature="e#856#857#0" expanded="true" />
|
||||||
|
<element signature="e#875#876#0" expanded="true" />
|
||||||
|
<element signature="e#1196#1197#0" expanded="true" />
|
||||||
|
<element signature="e#1221#1222#0" expanded="true" />
|
||||||
|
<element signature="e#1347#1348#0" expanded="true" />
|
||||||
|
<element signature="e#1366#1367#0" expanded="true" />
|
||||||
|
<element signature="e#1423#1424#0" expanded="true" />
|
||||||
|
<element signature="e#1442#1443#0" expanded="true" />
|
||||||
|
<element signature="e#1599#1600#0" expanded="true" />
|
||||||
|
<element signature="e#1615#1616#0" expanded="true" />
|
||||||
|
</folding>
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
<entry file="file://$PROJECT_DIR$/blog/src/main.rs">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state relative-caret-position="224">
|
||||||
|
<caret line="14" lean-forward="true" selection-start-line="14" selection-end-line="14" />
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
7
blog/Cargo.toml
Normal file
7
blog/Cargo.toml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
[package]
|
||||||
|
name = "blog"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Timothy Warren <twarren@nabancard.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[dependencies]
|
81
blog/src/lib.rs
Normal file
81
blog/src/lib.rs
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
pub struct Post {
|
||||||
|
state: Option<Box<dyn State>>,
|
||||||
|
content: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Post {
|
||||||
|
pub fn new() -> Post {
|
||||||
|
Post {
|
||||||
|
state: Some(Box::new(Draft {})),
|
||||||
|
content: String::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_text(&mut self, text: &str) {
|
||||||
|
self.content.push_str(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn content(&self) -> &str {
|
||||||
|
self.state.as_ref().unwrap().content(&self)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn request_review(&mut self) {
|
||||||
|
if let Some(s) = self.state.take() {
|
||||||
|
self.state = Some(s.request_review())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn approve(&mut self) {
|
||||||
|
if let Some(s) = self.state.take() {
|
||||||
|
self.state = Some(s.approve())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
trait State {
|
||||||
|
fn request_review(self: Box<Self>) -> Box<dyn State>;
|
||||||
|
fn approve(self: Box<Self>) -> Box<dyn State>;
|
||||||
|
fn content<'a>(&self, post: &'a Post) -> &'a str {
|
||||||
|
""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Draft {}
|
||||||
|
|
||||||
|
impl State for Draft {
|
||||||
|
fn request_review(self: Box<Self>) -> Box<dyn State> {
|
||||||
|
Box::new(PendingReview {})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn approve(self: Box<Self>) -> Box<dyn State> {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct PendingReview {}
|
||||||
|
|
||||||
|
impl State for PendingReview {
|
||||||
|
fn request_review(self: Box<Self>) -> Box<dyn State> {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
fn approve(self: Box<Self>) -> Box<dyn State> {
|
||||||
|
Box::new(Published {})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Published {}
|
||||||
|
|
||||||
|
impl State for Published {
|
||||||
|
fn request_review(self: Box<Self>) -> Box<dyn State> {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
fn approve(self: Box<Self>) -> Box<dyn State> {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
fn content<'a>(&self, post: &'a Post) -> &'a str {
|
||||||
|
&post.content
|
||||||
|
}
|
||||||
|
}
|
14
blog/src/main.rs
Normal file
14
blog/src/main.rs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
use blog::Post;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut post = Post::new();
|
||||||
|
|
||||||
|
post.add_text("I ate a salad for lunch today");
|
||||||
|
assert_eq!("", post.content());
|
||||||
|
|
||||||
|
post.request_review();
|
||||||
|
assert_eq!("", post.content());
|
||||||
|
|
||||||
|
post.approve();
|
||||||
|
assert_eq!("I ate a salad for lunch today", post.content());
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user