{"id":19219354,"url":"https://github.com/look/essential-rust-types","last_synced_at":"2026-03-01T17:33:15.812Z","repository":{"id":66441560,"uuid":"345481556","full_name":"look/essential-rust-types","owner":"look","description":null,"archived":false,"fork":false,"pushed_at":"2021-03-07T23:57:23.000Z","size":2,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-13T17:30:09.555Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/look.png","metadata":{"files":{"readme":"README.org","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-07T23:56:42.000Z","updated_at":"2021-03-07T23:57:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"13fa444b-b607-41cd-b17b-6c75f49e7293","html_url":"https://github.com/look/essential-rust-types","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/look/essential-rust-types","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/look%2Fessential-rust-types","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/look%2Fessential-rust-types/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/look%2Fessential-rust-types/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/look%2Fessential-rust-types/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/look","download_url":"https://codeload.github.com/look/essential-rust-types/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/look%2Fessential-rust-types/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29976279,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-01T16:35:47.903Z","status":"ssl_error","status_checked_at":"2026-03-01T16:35:44.899Z","response_time":124,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T14:30:56.354Z","updated_at":"2026-03-01T17:33:15.784Z","avatar_url":"https://github.com/look.png","language":null,"readme":"#+TITLE: Essential Rust Types\n#+STARTUP: showeverything\n#+STARTUP: indent\n#+OPTIONS: toc:nil\n#+OPTIONS: num:nil\n\n* Introduction\nRust is a language of types. When you are learning Rust and reading unfamiliar Rust code, you see a lot of type.  _Essential Rust Types_ is an attempt to provide a quick reference to the most commonly used types. It is not comprehensive ([[https://doc.rust-lang.org/std/][read the docs]] for that), but rather a learning tool.\n\nThe Rust types documented here come in three flavors: Traits, Structs, and Enums. Traits are Rust's version of interfaces and because they are used to define behavior for types (including custom user types) they are the most commonly documented here. Types are given fully qualified, unless they are part of the [[https://doc.rust-lang.org/std/prelude/index.html][standard prelude]].\n* Rust types\n** [[https://doc.rust-lang.org/std/clone/trait.Clone.html][~Clone~]]                                                           :trait:\n~Clone~ copies an object by running user-defined code, which may or may not be expensive.\n** [[https://doc.rust-lang.org/std/marker/trait.Copy.html][~Copy~]]                                                            :trait:\n~Copy~ is a [[https://doc.rust-lang.org/std/marker/index.html][marker trait]]. When a type implements ~Copy~, assignment does a bit-for-bit copy of values, rather than moving it. For example ~usize~ is ~Copy~ but ~Vec\u003cusize\u003e~ is not ~Copy~. \n\nYou can implement ~Copy~ for your own types as long as all members are also ~Copy~. ~Clone~ is a supertrait of ~Copy~, so everything implementing ~Copy~ must also implement ~Clone~.\n** FromIter\n#+BEGIN_QUOTE\nResult implements FromIter so that a vector of results (Vec\u003cResult\u003cT, E\u003e\u003e) can\nbe turned into a result with a vector (Result\u003cVec\u003cT\u003e, E\u003e). Once an Result::Err\nis found, the iteration will terminate.\n#+END_QUOTE\nhttps://doc.rust-lang.org/rust-by-example/error/iter_result.html\n** [[https://doc.rust-lang.org/std/option/enum.Option.html][~Option~]]                                                           :enum:\n~Option~ is an enum with two values, ~None~ and ~Some(T)~. Rust does not have ~null~ so ~None~ is used to indicate a missing value.\n\nOption can be pattern-matched:\n\n#+BEGIN_SRC\nx match {\n  Some(x) =\u003e println!(\"Got {}\", x),\n  None =\u003e println!(\"Not found!\"),\n};\n#+END_SRC\n\nUsed in [[https://doc.rust-lang.org/rust-by-example/flow_control/if_let.html][~if let~]] statements:\n\n#+BEGIN_SRC\nif let Some(x) = y {\n  println!(\"Do something with x\");\n}\n#+END_SRC\n\nAnd ~Option~ has several useful methods for working with values, including ~map~, ~map_or~, ~and_then~, and ~filter~. ~ok_or~ and ~ok_or_else~ allow converting an ~Option~ into a ~Result~.\n\nOption can also be unwrapped using ~unwrap~ and ~expect~. When called on a ~None~ value, this will cause a panic.\n** Sized\n** [[https://doc.rust-lang.org/std/default/trait.Default.html][~Default~]]                                           :trait:\nThe ~Default~ trait provides a default value for a type, similar to Go's zero value, using ~TypeName::default()~. Rust provides default value implementations for most primitive types (for example, [[https://doc.rust-lang.org/std/primitive.u16.html#impl-Default][here is the one for ~u16~ ]]). If all the types of a struct implement ~Default~, it can be derived with ~#[derive(Default)]~.\n\n** ~Box~\n~Box\u003cT\u003e~ is a heap-allocated pointer for ~T~. Box allows you to move a value from the stack to the heap. This is necessary for self-referential data types.\n** Error\nTrait for Error types, often returned in Result\u003cT, E\u003e\n** [[https://doc.rust-lang.org/std/fmt/trait.Debug.html][std::fmt::Debug]] :trait:\nFor use in string formatting with ~{:?}~ and ~{#?}~ (for pretty printing). ~Debug~ can automatically be derived as long as all the fields of a struct or enum are also ~Debug~:\n\n#+BEGIN_SRC\n#[derive(Debug)]\nstruct Person {\n  name: String,\n}\n#+END_SRC\n\nTo implement ~Debug~ yourself, you must provide a ~fmt~ method.\n\nIn general, you should define ~Debug~ for your types.\n** [[https://doc.rust-lang.org/std/fmt/trait.Display.html][~std::fmt::Display~]]                                               :trait:\nImplement ~Display~ for your types to use string formatting with ~{}~. It provides the ~to_string()~ method because implementing ~Display~ automatically implements [[https://doc.rust-lang.org/std/string/trait.ToString.html][~ToString~]].\n\n~Display~ is similar to ~Debug~ but it cannot be derived automatically because it is intended for user-facing display.\n** String :struct:\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flook%2Fessential-rust-types","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flook%2Fessential-rust-types","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flook%2Fessential-rust-types/lists"}