Add advanced_functions example
This commit is contained in:
parent
9a23a0ce9b
commit
59bc706d0a
@ -40,6 +40,7 @@
|
||||
<cargoProject FILE="$PROJECT_DIR$/advanced_lifetimes/Cargo.toml" />
|
||||
<cargoProject FILE="$PROJECT_DIR$/advanced_traits/Cargo.toml" />
|
||||
<cargoProject FILE="$PROJECT_DIR$/advanced_types/Cargo.toml" />
|
||||
<cargoProject FILE="$PROJECT_DIR$/advanced_functions/Cargo.toml" />
|
||||
</component>
|
||||
<component name="ComposerJsonPluginSettings">
|
||||
<unboundedVersionInspectionSettings>
|
||||
|
@ -161,9 +161,14 @@
|
||||
<sourceFolder url="file://$MODULE_DIR$/advanced_types/examples" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/advanced_types/tests" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/advanced_types/benches" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/advanced_functions/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/advanced_functions/examples" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/advanced_functions/tests" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/advanced_functions/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" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/advanced_functions/target" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/advanced_lifetimes/target" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/advanced_traits/target" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/advanced_types/target" />
|
||||
|
@ -15,10 +15,18 @@
|
||||
<component name="FileEditorManager">
|
||||
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
|
||||
<file pinned="false" current-in-tab="true">
|
||||
<entry file="file://$PROJECT_DIR$/advanced_types/src/main.rs">
|
||||
<entry file="file://$PROJECT_DIR$/advanced_functions/src/main.rs">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="256">
|
||||
<caret line="16" selection-start-line="16" selection-end-line="16" />
|
||||
<state relative-caret-position="544">
|
||||
<caret line="34" column="25" selection-start-line="34" selection-start-column="25" selection-end-line="34" selection-end-column="25" />
|
||||
<folding>
|
||||
<element signature="e#26#27#0" expanded="true" />
|
||||
<element signature="e#38#39#0" expanded="true" />
|
||||
<element signature="e#89#90#0" expanded="true" />
|
||||
<element signature="e#112#113#0" expanded="true" />
|
||||
<element signature="e#271#272#0" expanded="true" />
|
||||
<element signature="e#291#292#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
@ -52,7 +60,6 @@
|
||||
<component name="IdeDocumentHistory">
|
||||
<option name="CHANGED_PATHS">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/guessing_game/.gitignore" />
|
||||
<option value="$PROJECT_DIR$/errors/src/main.rs" />
|
||||
<option value="$PROJECT_DIR$/.gitignore" />
|
||||
<option value="$PROJECT_DIR$/largest_number/src/main.rs" />
|
||||
@ -103,6 +110,7 @@
|
||||
<option value="$PROJECT_DIR$/advanced_traits/src/lib.rs" />
|
||||
<option value="$PROJECT_DIR$/advanced_traits/src/main.rs" />
|
||||
<option value="$PROJECT_DIR$/advanced_types/src/main.rs" />
|
||||
<option value="$PROJECT_DIR$/advanced_functions/src/main.rs" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
@ -112,7 +120,7 @@
|
||||
<annotation-enable>false</annotation-enable>
|
||||
<other-services-enabled>false</other-services-enabled>
|
||||
</component>
|
||||
<component name="ProjectFrameBounds">
|
||||
<component name="ProjectFrameBounds" extendedState="6">
|
||||
<option name="x" value="1920" />
|
||||
<option name="y" value="-438" />
|
||||
<option name="width" value="1080" />
|
||||
@ -159,12 +167,12 @@
|
||||
<path>
|
||||
<item name="rust" type="3d21c010:ScopeViewTreeModel$ProjectNode" />
|
||||
<item name="rust" type="2674bda8:ScopeViewTreeModel$GroupNode" />
|
||||
<item name="advanced_types" type="9f88c78c:ScopeViewTreeModel$FileNode" />
|
||||
<item name="advanced_functions" type="9f88c78c:ScopeViewTreeModel$FileNode" />
|
||||
</path>
|
||||
<path>
|
||||
<item name="rust" type="3d21c010:ScopeViewTreeModel$ProjectNode" />
|
||||
<item name="rust" type="2674bda8:ScopeViewTreeModel$GroupNode" />
|
||||
<item name="advanced_types" type="9f88c78c:ScopeViewTreeModel$FileNode" />
|
||||
<item name="advanced_functions" type="9f88c78c:ScopeViewTreeModel$FileNode" />
|
||||
<item name="src" type="9f88c78c:ScopeViewTreeModel$FileNode" />
|
||||
</path>
|
||||
</expand>
|
||||
@ -175,7 +183,7 @@
|
||||
</component>
|
||||
<component name="PropertiesComponent">
|
||||
<property name="JavaScriptWeakerCompletionTypeGuess" value="true" />
|
||||
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1549652604126" />
|
||||
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1549895652600" />
|
||||
<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" />
|
||||
@ -203,7 +211,7 @@
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="RunManager" selected="Cargo Command.Run advanced_types">
|
||||
<component name="RunManager" selected="Cargo Command.Run advanced_functions">
|
||||
<configuration name="<template>" type="TestNG" default="true" selected="false">
|
||||
<option name="MAIN_CLASS_NAME" />
|
||||
<option name="VM_PARAMETERS" value="-ea" />
|
||||
@ -222,6 +230,16 @@
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration name="Run advanced_functions" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
|
||||
<option name="channel" value="DEFAULT" />
|
||||
<option name="command" value="run --package advanced_functions --bin advanced_functions" />
|
||||
<option name="allFeatures" value="false" />
|
||||
<option name="nocapture" value="false" />
|
||||
<option name="backtrace" value="SHORT" />
|
||||
<option name="workingDirectory" value="file://$PROJECT_DIR$/advanced_functions" />
|
||||
<envs />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
<configuration name="Run advanced_lifetimes" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
|
||||
<option name="channel" value="DEFAULT" />
|
||||
<option name="command" value="run --package advanced_lifetimes --bin advanced_lifetimes" />
|
||||
@ -262,16 +280,6 @@
|
||||
<envs />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
<configuration name="Test tests::it_works" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
|
||||
<option name="channel" value="DEFAULT" />
|
||||
<option name="command" value="test --package advanced_lifetimes --lib tests::it_works -- --exact" />
|
||||
<option name="allFeatures" value="false" />
|
||||
<option name="nocapture" value="false" />
|
||||
<option name="backtrace" value="SHORT" />
|
||||
<option name="workingDirectory" value="file://$PROJECT_DIR$/advanced_lifetimes" />
|
||||
<envs />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
<configuration default="true" type="JUnit" factoryName="JUnit">
|
||||
<option name="TEST_OBJECT" value="class" />
|
||||
<option name="WORKING_DIRECTORY" value="$MODULE_DIR$" />
|
||||
@ -281,11 +289,11 @@
|
||||
</configuration>
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<item itemvalue="Cargo Command.Run advanced_functions" />
|
||||
<item itemvalue="Cargo Command.Run advanced_types" />
|
||||
<item itemvalue="Cargo Command.Run advanced_traits" />
|
||||
<item itemvalue="Cargo Command.Run advanced_lifetimes" />
|
||||
<item itemvalue="Cargo Command.Test lib::tests" />
|
||||
<item itemvalue="Cargo Command.Test tests::it_works" />
|
||||
</list>
|
||||
</recent_temporary>
|
||||
</component>
|
||||
@ -325,8 +333,8 @@
|
||||
<frame x="1920" y="-438" width="1080" height="1897" extended-state="6" />
|
||||
<editor active="true" />
|
||||
<layout>
|
||||
<window_info active="true" content_ui="combo" id="Project" order="0" sideWeight="0.4958077" visible="true" weight="0.2540132" />
|
||||
<window_info id="Structure" order="1" sideWeight="0.5041923" side_tool="true" visible="true" weight="0.2540132" />
|
||||
<window_info content_ui="combo" id="Project" order="0" sideWeight="0.49586156" visible="true" weight="0.2540132" />
|
||||
<window_info id="Structure" order="1" sideWeight="0.50413847" side_tool="true" visible="true" weight="0.2540132" />
|
||||
<window_info id="Image Layers" order="2" />
|
||||
<window_info id="Designer" order="3" />
|
||||
<window_info id="Capture Tool" order="4" />
|
||||
@ -334,7 +342,7 @@
|
||||
<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="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.2571269" />
|
||||
<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="Inspection" order="5" weight="0.4" />
|
||||
@ -356,17 +364,6 @@
|
||||
<option name="version" value="1" />
|
||||
</component>
|
||||
<component name="editorHistoryManager">
|
||||
<entry file="file://$PROJECT_DIR$/modules/src/sound/instrument.rs">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="48">
|
||||
<caret line="3" lean-forward="true" selection-start-line="3" selection-end-line="3" />
|
||||
<folding>
|
||||
<element signature="e#18#19#0" expanded="true" />
|
||||
<element signature="e#60#61#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/modules/src/performance_group.rs">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="96">
|
||||
@ -563,13 +560,6 @@
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/add/Cargo.toml">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="96">
|
||||
<caret line="6" selection-start-line="6" selection-end-line="6" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/add/adder/src/main.rs">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="64">
|
||||
@ -804,7 +794,29 @@
|
||||
<entry file="file://$PROJECT_DIR$/advanced_types/src/main.rs">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="256">
|
||||
<caret line="16" selection-start-line="16" selection-end-line="16" />
|
||||
<caret line="16" lean-forward="true" selection-start-line="16" selection-end-line="16" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/add/Cargo.toml">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="96">
|
||||
<caret line="6" lean-forward="true" selection-start-line="6" selection-end-line="6" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/advanced_functions/src/main.rs">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="544">
|
||||
<caret line="34" column="25" selection-start-line="34" selection-start-column="25" selection-end-line="34" selection-end-column="25" />
|
||||
<folding>
|
||||
<element signature="e#26#27#0" expanded="true" />
|
||||
<element signature="e#38#39#0" expanded="true" />
|
||||
<element signature="e#89#90#0" expanded="true" />
|
||||
<element signature="e#112#113#0" expanded="true" />
|
||||
<element signature="e#271#272#0" expanded="true" />
|
||||
<element signature="e#291#292#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
|
7
advanced_functions/Cargo.toml
Normal file
7
advanced_functions/Cargo.toml
Normal file
@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "advanced_functions"
|
||||
version = "0.1.0"
|
||||
authors = ["Timothy Warren <twarren@nabancard.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
38
advanced_functions/src/main.rs
Normal file
38
advanced_functions/src/main.rs
Normal file
@ -0,0 +1,38 @@
|
||||
fn add_one(x: i32) -> i32 {
|
||||
x + 1
|
||||
}
|
||||
|
||||
/// A function with a function pointer argument
|
||||
fn do_twice(f: fn(i32) -> i32, arg: i32) -> i32 {
|
||||
f(arg) + f(arg)
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Status {
|
||||
Value(u32),
|
||||
Stop,
|
||||
}
|
||||
|
||||
fn returns_closure() -> Box<dyn Fn (i32) -> i32> {
|
||||
Box::new(|x| x + 1)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let answer = do_twice(add_one, 5);
|
||||
|
||||
println!("The answer is: {}", answer);
|
||||
|
||||
// Tuple Structs set up via function pointers
|
||||
let list_of_statuses: Vec<Status> =
|
||||
(0u32..20)
|
||||
.map(Status::Value)
|
||||
.collect();
|
||||
|
||||
println!("List of statuses: {:?}", list_of_statuses);
|
||||
|
||||
let increment = returns_closure();
|
||||
let x = 5;
|
||||
let y = increment(x);
|
||||
|
||||
println!("The returned closure returns: {}", y);
|
||||
}
|
Loading…
Reference in New Issue
Block a user