Add reference_counting example

This commit is contained in:
Timothy Warren 2019-02-05 10:22:35 -05:00
parent 9b0fff8c9f
commit f9dcd6d48d
5 changed files with 60 additions and 36 deletions

View File

@ -25,6 +25,7 @@
<cargoProject FILE="$PROJECT_DIR$/minigrep_v2/Cargo.toml" />
<cargoProject FILE="$PROJECT_DIR$/add/Cargo.toml" />
<cargoProject FILE="$PROJECT_DIR$/smart_pointers/Cargo.toml" />
<cargoProject FILE="$PROJECT_DIR$/reference_counting/Cargo.toml" />
</component>
<component name="ComposerJsonPluginSettings">
<unboundedVersionInspectionSettings>

View File

@ -102,6 +102,10 @@
<sourceFolder url="file://$MODULE_DIR$/smart_pointers/examples" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/smart_pointers/tests" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/smart_pointers/benches" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/reference_counting/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/reference_counting/examples" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/reference_counting/tests" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/reference_counting/benches" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/add/add-one/target" />
<excludeFolder url="file://$MODULE_DIR$/add/adder/target" />
<excludeFolder url="file://$MODULE_DIR$/adder/target" />
@ -120,6 +124,7 @@
<excludeFolder url="file://$MODULE_DIR$/minigrep_v2/target" />
<excludeFolder url="file://$MODULE_DIR$/modules/target" />
<excludeFolder url="file://$MODULE_DIR$/rectangles/target" />
<excludeFolder url="file://$MODULE_DIR$/reference_counting/target" />
<excludeFolder url="file://$MODULE_DIR$/references/target" />
<excludeFolder url="file://$MODULE_DIR$/scope/target" />
<excludeFolder url="file://$MODULE_DIR$/slices/target" />

View File

@ -15,29 +15,14 @@
<component name="FileEditorManager">
<leaf>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/smart_pointers/src/main.rs">
<entry file="file://$PROJECT_DIR$/reference_counting/src/main.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="32">
<caret line="2" lean-forward="true" selection-start-line="2" selection-end-line="2" />
<folding>
<element signature="e#68#69#0" expanded="true" />
<element signature="e#91#92#0" expanded="true" />
<element signature="e#200#201#0" expanded="true" />
<element signature="e#216#217#0" expanded="true" />
<element signature="e#351#352#0" expanded="true" />
<element signature="e#433#434#0" expanded="true" />
<element signature="e#244#245#0" expanded="true" />
<element signature="e#261#262#0" expanded="true" />
</folding>
<state relative-caret-position="224">
<caret line="14" column="13" selection-start-line="14" selection-start-column="13" selection-end-line="14" selection-end-column="13" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/smart_pointers/src/lib.rs">
<provider selected="true" editor-type-id="text-editor" />
</entry>
</file>
</leaf>
</component>
<component name="FileTemplateManagerImpl">
@ -107,6 +92,7 @@
<option value="$PROJECT_DIR$/add/add-one/src/lib.rs" />
<option value="$PROJECT_DIR$/smart_pointers/src/lib.rs" />
<option value="$PROJECT_DIR$/smart_pointers/src/main.rs" />
<option value="$PROJECT_DIR$/reference_counting/src/main.rs" />
</list>
</option>
</component>
@ -140,12 +126,12 @@
<path>
<item name="rust" type="3d21c010:ScopeViewTreeModel$ProjectNode" />
<item name="rust" type="2674bda8:ScopeViewTreeModel$GroupNode" />
<item name="smart_pointers" type="9f88c78c:ScopeViewTreeModel$FileNode" />
<item name="reference_counting" type="9f88c78c:ScopeViewTreeModel$FileNode" />
</path>
<path>
<item name="rust" type="3d21c010:ScopeViewTreeModel$ProjectNode" />
<item name="rust" type="2674bda8:ScopeViewTreeModel$GroupNode" />
<item name="smart_pointers" type="9f88c78c:ScopeViewTreeModel$FileNode" />
<item name="reference_counting" type="9f88c78c:ScopeViewTreeModel$FileNode" />
<item name="src" type="9f88c78c:ScopeViewTreeModel$FileNode" />
</path>
</expand>
@ -179,7 +165,7 @@
</component>
<component name="PropertiesComponent">
<property name="JavaScriptWeakerCompletionTypeGuess" value="true" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1549379395077" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1549380100372" />
<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.nodeInterpreter" value="project" />
@ -207,7 +193,7 @@
</list>
</option>
</component>
<component name="RunManager" selected="Cargo Command.Run smart_pointers">
<component name="RunManager" selected="Cargo Command.Run reference_counting">
<configuration name="&lt;template&gt;" type="TestNG" default="true" selected="false">
<option name="MAIN_CLASS_NAME" />
<option name="VM_PARAMETERS" value="-ea" />
@ -226,6 +212,16 @@
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="Run reference_counting" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
<option name="channel" value="DEFAULT" />
<option name="command" value="run --package reference_counting --bin reference_counting" />
<option name="allFeatures" value="false" />
<option name="nocapture" value="false" />
<option name="backtrace" value="SHORT" />
<option name="workingDirectory" value="file://$PROJECT_DIR$/reference_counting" />
<envs />
<method v="2" />
</configuration>
<configuration name="Run smart_pointers" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
<option name="channel" value="DEFAULT" />
<option name="command" value="run --package smart_pointers --bin smart_pointers" />
@ -246,16 +242,6 @@
<envs />
<method v="2" />
</configuration>
<configuration name="Test filters_by_size" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
<option name="channel" value="DEFAULT" />
<option name="command" value="test --package closures --lib filters_by_size -- --exact" />
<option name="allFeatures" value="false" />
<option name="nocapture" value="false" />
<option name="backtrace" value="SHORT" />
<option name="workingDirectory" value="file://$PROJECT_DIR$/closures" />
<envs />
<method v="2" />
</configuration>
<configuration name="Test lib::tests (1)" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
<option name="channel" value="DEFAULT" />
<option name="command" value="test --package minigrep_v2 --lib tests" />
@ -285,11 +271,11 @@
</configuration>
<recent_temporary>
<list>
<item itemvalue="Cargo Command.Run reference_counting" />
<item itemvalue="Cargo Command.Run smart_pointers" />
<item itemvalue="Cargo Command.Test lib::tests (1)" />
<item itemvalue="Cargo Command.Test using_other_iterator_trait_methods" />
<item itemvalue="Cargo Command.Test calling_next_directly" />
<item itemvalue="Cargo Command.Test filters_by_size" />
</list>
</recent_temporary>
</component>
@ -731,13 +717,12 @@
</entry>
<entry file="file://$PROJECT_DIR$/smart_pointers/src/main.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="32">
<caret line="2" lean-forward="true" selection-start-line="2" selection-end-line="2" />
<state relative-caret-position="256">
<caret line="16" column="4" selection-start-line="16" selection-start-column="4" selection-end-line="16" selection-end-column="4" />
<folding>
<element signature="e#68#69#0" expanded="true" />
<element signature="e#91#92#0" expanded="true" />
<element signature="e#200#201#0" expanded="true" />
<element signature="e#216#217#0" expanded="true" />
<element signature="e#351#352#0" expanded="true" />
<element signature="e#433#434#0" expanded="true" />
<element signature="e#244#245#0" expanded="true" />
@ -746,5 +731,12 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/reference_counting/src/main.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="224">
<caret line="14" column="13" selection-start-line="14" selection-start-column="13" selection-end-line="14" selection-end-column="13" />
</state>
</provider>
</entry>
</component>
</project>

View File

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

View File

@ -0,0 +1,19 @@
enum List {
Cons(i32, Rc<List>),
Nil,
}
use List::{Cons, Nil};
use std::rc::Rc;
fn main() {
let a = Rc::new(Cons(5, Rc::new(Cons(10, Rc::new(Nil)))));
println!("count after creating a = {}", Rc::strong_count(&a));
let _b = Cons(3, Rc::clone(&a));
println!("count after creating b = {}", Rc::strong_count(&a));
{
let _c = Cons(4, Rc::clone(&a));
println!("count after creating c = {}", Rc::strong_count(&a));
}
println!("count after c goes out of scope = {}", Rc::strong_count(&a));
}