From 5725ea4a90a9809fd3c42b28ac69403cbb4b2a35 Mon Sep 17 00:00:00 2001 From: darkicewolf50 Date: Thu, 9 Jan 2025 21:43:37 -0700 Subject: [PATCH] ch7.0 + 7.1 finished --- .obsidian/workspace.json | 40 +++++++++++++++++++++-------- Crates.md | 33 ++++++++++++++++++++++++ Modules.md | 1 - Packages.md | 11 ++++++++ Project Organization.md | 18 +++++++++++++ hello_cargo/target/.rustc_info.json | 2 +- 6 files changed, 93 insertions(+), 12 deletions(-) create mode 100644 Crates.md delete mode 100644 Modules.md create mode 100644 Packages.md create mode 100644 Project Organization.md diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json index 3c720f3..de7934c 100644 --- a/.obsidian/workspace.json +++ b/.obsidian/workspace.json @@ -27,12 +27,27 @@ "state": { "type": "markdown", "state": { - "file": "Modules.md", + "file": "Project Organization.md", "mode": "source", "source": false }, "icon": "lucide-file", - "title": "Modules" + "title": "Project Organization" + } + }, + { + "id": "773e0725828dabb7", + "type": "leaf", + "state": { + "type": "markdown", + "state": { + "file": "Crates.md", + "mode": "source", + "backlinks": false, + "source": false + }, + "icon": "lucide-file", + "title": "Crates" } }, { @@ -50,7 +65,7 @@ } } ], - "currentTab": 1 + "currentTab": 2 } ], "direction": "vertical" @@ -106,7 +121,7 @@ } ], "direction": "horizontal", - "width": 300 + "width": 241.5 }, "right": { "id": "b825b33a537311a6", @@ -192,14 +207,19 @@ "command-palette:Open command palette": false } }, - "active": "b80f5219fa24358f", + "active": "773e0725828dabb7", "lastOpenFiles": [ - "data_types.md", - "Modules.md", - "Data Types.md", - "Primitives.md", - "ownership.md", + "Packages.md", + "Crates.md", + "Project Organization.md", "Enums.md", + "Primitives.md", + "Packages and Crates.md", + "Good and Bad Code/Commenting Pratices", + "Good and Bad Code", + "data_types.md", + "Data Types.md", + "ownership.md", "Variables.md", "README.md", "Untitled.canvas", diff --git a/Crates.md b/Crates.md new file mode 100644 index 0000000..a297b4b --- /dev/null +++ b/Crates.md @@ -0,0 +1,33 @@ +# Crates +The smallest amount of code that the rust compiler will consider + +This includes single binary exe files compiled with ``rustc`` + +``cargo build`` also counts and so does ``cargo run`` (implicit ``cargo build``) + +Crates can contain modules and modules may be defined in other files that get compiled with the crate + +It comes in two forms a library or a binary + +## Binary Crates +are programs that can be compiled then run like a cli application or a server +each must have main function that defines what happens when the executable runs + +## Library Crates +are programs that don't have a main function and don't compile to a executable +instead it defines functionality that is intended to be shared with multiple projects + +most of the time when the term "crate" is said it means a library crate +and crate is used interchangeably with the term library with other languages + + +## Root Crate +this is the source file that the compiler starts from and makes up the root module of your crate + +this is normally src/main.rs in a binary crate +scr/lib.rs is normally the root in a library crate with the same name as the package +hence why it doesn't need to be mentioned in the toml file this tells you what the packages are + +cargo passes root crates to rustc to build the library or the binary + +by replacing files in the src/bin directory each file will be its own binary crate \ No newline at end of file diff --git a/Modules.md b/Modules.md deleted file mode 100644 index 016d434..0000000 --- a/Modules.md +++ /dev/null @@ -1 +0,0 @@ -# Modules \ No newline at end of file diff --git a/Packages.md b/Packages.md new file mode 100644 index 0000000..cb471ed --- /dev/null +++ b/Packages.md @@ -0,0 +1,11 @@ +# Packages + +a bundle of one or more crates that provides a set functionality + +it contains a cargo.toml file and describes how to build those crates + +packages can have as many binary crates as you want but only at most one library crate + +packages must have at least one crate + +packages are defined by the toml file that comes with creating a new crate \ No newline at end of file diff --git a/Project Organization.md b/Project Organization.md new file mode 100644 index 0000000..51cad51 --- /dev/null +++ b/Project Organization.md @@ -0,0 +1,18 @@ +# Packages, Modules and Crates + +Projects should generally group related code/function together this increases code organization + +packages can contain multiple binary codes/files or a library crate + +very large projects should be done with interrelated packages that all update should be done using cargo workspaces + +encapsulation is useful because you don't need to worry about its implementation +this is good for reusing code + +rust has features for your code's organization, which parts are exposed, which details are private and what names are in each scope in the program + +These features are known collectively as the ``module system`` they include +- [**Packages**](Packages.md): A feature of Cargo that allows you to build, test and share crates +- [**Crates**](Crates.md): A tree of modules that produces a library or an executable +- **Modules** and **use**: lets you control the organization, scope and privacy of paths +- **Paths**: A way of naming an item, such as a struct, function or module diff --git a/hello_cargo/target/.rustc_info.json b/hello_cargo/target/.rustc_info.json index 2df2597..b287c23 100644 --- a/hello_cargo/target/.rustc_info.json +++ b/hello_cargo/target/.rustc_info.json @@ -1 +1 @@ -{"rustc_fingerprint":13662911779824945272,"outputs":{"12744816824612481171":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\nC:\\Users\\Brock\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\npacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"msvc\"\ntarget_family=\"windows\"\ntarget_feature=\"cmpxchg16b\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_feature=\"sse3\"\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"windows\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"pc\"\nwindows\n","stderr":""},"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.83.0 (90b35a623 2024-11-26)\nbinary: rustc\ncommit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\ncommit-date: 2024-11-26\nhost: x86_64-pc-windows-msvc\nrelease: 1.83.0\nLLVM version: 19.1.1\n","stderr":""},"15729799797837862367":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\nC:\\Users\\Brock\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\npacked\n___\ndebug_assertions\nfmt_debug=\"full\"\noverflow_checks\npanic=\"unwind\"\nproc_macro\nrelocation_model=\"pic\"\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"msvc\"\ntarget_family=\"windows\"\ntarget_feature=\"cmpxchg16b\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"lahfsahf\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_feature=\"sse3\"\ntarget_has_atomic\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_has_atomic_equal_alignment=\"128\"\ntarget_has_atomic_equal_alignment=\"16\"\ntarget_has_atomic_equal_alignment=\"32\"\ntarget_has_atomic_equal_alignment=\"64\"\ntarget_has_atomic_equal_alignment=\"8\"\ntarget_has_atomic_equal_alignment=\"ptr\"\ntarget_has_atomic_load_store\ntarget_has_atomic_load_store=\"128\"\ntarget_has_atomic_load_store=\"16\"\ntarget_has_atomic_load_store=\"32\"\ntarget_has_atomic_load_store=\"64\"\ntarget_has_atomic_load_store=\"8\"\ntarget_has_atomic_load_store=\"ptr\"\ntarget_os=\"windows\"\ntarget_pointer_width=\"64\"\ntarget_thread_local\ntarget_vendor=\"pc\"\nub_checks\nwindows\n","stderr":""}},"successes":{}} \ No newline at end of file +{"rustc_fingerprint":13662911779824945272,"outputs":{"15729799797837862367":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\nC:\\Users\\Brock\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\npacked\n___\ndebug_assertions\nfmt_debug=\"full\"\noverflow_checks\npanic=\"unwind\"\nproc_macro\nrelocation_model=\"pic\"\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"msvc\"\ntarget_family=\"windows\"\ntarget_feature=\"cmpxchg16b\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"lahfsahf\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_feature=\"sse3\"\ntarget_has_atomic\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_has_atomic_equal_alignment=\"128\"\ntarget_has_atomic_equal_alignment=\"16\"\ntarget_has_atomic_equal_alignment=\"32\"\ntarget_has_atomic_equal_alignment=\"64\"\ntarget_has_atomic_equal_alignment=\"8\"\ntarget_has_atomic_equal_alignment=\"ptr\"\ntarget_has_atomic_load_store\ntarget_has_atomic_load_store=\"128\"\ntarget_has_atomic_load_store=\"16\"\ntarget_has_atomic_load_store=\"32\"\ntarget_has_atomic_load_store=\"64\"\ntarget_has_atomic_load_store=\"8\"\ntarget_has_atomic_load_store=\"ptr\"\ntarget_os=\"windows\"\ntarget_pointer_width=\"64\"\ntarget_thread_local\ntarget_vendor=\"pc\"\nub_checks\nwindows\n","stderr":""},"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.83.0 (90b35a623 2024-11-26)\nbinary: rustc\ncommit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\ncommit-date: 2024-11-26\nhost: x86_64-pc-windows-msvc\nrelease: 1.83.0\nLLVM version: 19.1.1\n","stderr":""},"12744816824612481171":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\nC:\\Users\\Brock\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\npacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"msvc\"\ntarget_family=\"windows\"\ntarget_feature=\"cmpxchg16b\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_feature=\"sse3\"\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"windows\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"pc\"\nwindows\n","stderr":""}},"successes":{}} \ No newline at end of file