String type | Description | Reference |
---|---|---|
String | A collection of utf-8 characters, stored in the heap and managed with a control block on the stack. | std::String |
&str | A collection of utf-8 characters in a contiguous block on the stack, sometimes in static memory too. | std::str |
OsString | Same structure as std::String, but holding characters from the platform string type, used most often to interoperate with C code through Rust's foreign function interface (ffi). | std::ffi::OsString |
OsStr | A literal string with the same character encoding as OsString. | std::ffi::OsStr |
PathBuf | Same structure as std::String, but holding characters from the platform string type, and providing methods for working with paths, e.g., extracting names, extensions, doing joins, etc. | std::path::PathBuf |
&Path | A literal string with the same character encoding as PathBuf. | std::path::Path |
Topic | Description | Link |
---|---|---|
File System |
Rust has a well engineered facility for accessing files and directories. Some key types in std::fs are: DirEntry, File, OpenOptions, ReadDir, ... |
Rust story File System std::fs |
Error Handling |
Rust error handling is based on use of the enumeration:
|
RustStory Enums RustStory Error Handling Gentle Introduction to Rust std::Result |
Generics | Generics in Rust are very similar to those in C# and Java, and simpler than C++ templates. They are code generators often do little more than substitute a specific type for a generic parameter. Rust generics are often constrained with traits, as discussed above. |
Rust Story Generics Rust Bites Generics and Traits The Rust Book |
DesignBites |
A sequence of discussions of design structure alternatives with illustrating code:
Monolitic, Factored, DataFlow, Type Erasure, Plug-In
|
Structure alternatives Data Flow Type Erasure |
Start with first three refs, above. Rest will be useful later. | ||
Ownership | Rusts ownership rules: There is only one owner for any resource. Owners deallocate their resources when they go out of scope. Ownership can be transferred with a Move or borrowed with a reference. References don't own resources, they just borrow them, and so never deallocate. Rust ownership does not support simultaneously aliasing and mutation. |
Rust Bites Ownership Rust Story Ownership By Example Rust Book Rust Nomicon |
Strings |
Rust std strings come in two flavors: |
std::path std::path::PathBuf std::path::Path Rust by Example |
struct | Rust structs serve the same role as classes do in C++ and C#. Struct methods are defined inside impl StructName {} blocks. |
Rust Story structs std::Stuct keyword impl |