diff --git a/src/idiomatic/leveraging-the-type-system/extension-traits/extending-other-traits.md b/src/idiomatic/leveraging-the-type-system/extension-traits/extending-other-traits.md index 25f38425805a..53b3e46c2693 100644 --- a/src/idiomatic/leveraging-the-type-system/extension-traits/extending-other-traits.md +++ b/src/idiomatic/leveraging-the-type-system/extension-traits/extending-other-traits.md @@ -12,7 +12,7 @@ SPDX-License-Identifier: CC-BY-4.0 As with types, it may be desirable to **extend foreign traits**. In particular, to attach new methods to _all_ implementors of a given trait. -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/leveraging-the-type-system/newtype-pattern/is-it-encapsulated.md b/src/idiomatic/leveraging-the-type-system/newtype-pattern/is-it-encapsulated.md index 364a51905535..57d3e26e731d 100644 --- a/src/idiomatic/leveraging-the-type-system/newtype-pattern/is-it-encapsulated.md +++ b/src/idiomatic/leveraging-the-type-system/newtype-pattern/is-it-encapsulated.md @@ -14,7 +14,7 @@ invariants are indeed bullet-proof. It is crucial to consider all possible interactions, including trait implementations, that may allow users to bypass validation checks. -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/leveraging-the-type-system/newtype-pattern/parse-don-t-validate.md b/src/idiomatic/leveraging-the-type-system/newtype-pattern/parse-don-t-validate.md index bcc236d20479..ed06bb4e2d61 100644 --- a/src/idiomatic/leveraging-the-type-system/newtype-pattern/parse-don-t-validate.md +++ b/src/idiomatic/leveraging-the-type-system/newtype-pattern/parse-don-t-validate.md @@ -11,7 +11,7 @@ SPDX-License-Identifier: CC-BY-4.0 The newtype pattern can be leveraged to enforce _invariants_. -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/leveraging-the-type-system/newtype-pattern/semantic-confusion.md b/src/idiomatic/leveraging-the-type-system/newtype-pattern/semantic-confusion.md index dc727bd58545..18eb438e6b43 100644 --- a/src/idiomatic/leveraging-the-type-system/newtype-pattern/semantic-confusion.md +++ b/src/idiomatic/leveraging-the-type-system/newtype-pattern/semantic-confusion.md @@ -12,7 +12,7 @@ SPDX-License-Identifier: CC-BY-4.0 When a function takes multiple arguments of the same type, call sites are unclear: -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # @@ -31,7 +31,7 @@ login(password, username); The newtype pattern can prevent this class of errors at compile time: -```rust,compile_fail +```rust,editable,compile_fail # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/leveraging-the-type-system/raii/drop_guards.md b/src/idiomatic/leveraging-the-type-system/raii/drop_guards.md index cf97e4bbf2b1..26ca9f475924 100644 --- a/src/idiomatic/leveraging-the-type-system/raii/drop_guards.md +++ b/src/idiomatic/leveraging-the-type-system/raii/drop_guards.md @@ -13,7 +13,7 @@ A **drop guard** in Rust is a temporary object that performs some kind of cleanup when it goes out of scope. In the case of `Mutex`, the `lock` method returns a `MutexGuard` that automatically unlocks the mutex on `drop`: -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/leveraging-the-type-system/raii/mutex.md b/src/idiomatic/leveraging-the-type-system/raii/mutex.md index a277e3df61c1..ec687c65a705 100644 --- a/src/idiomatic/leveraging-the-type-system/raii/mutex.md +++ b/src/idiomatic/leveraging-the-type-system/raii/mutex.md @@ -14,7 +14,7 @@ descriptors. With a `Mutex`, the "resource" is mutable access to a value. You access the value by calling `lock`, which then returns a `MutexGuard` which will unlock the `Mutex` automatically when dropped. -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/leveraging-the-type-system/token-types/branded-03-impl.md b/src/idiomatic/leveraging-the-type-system/token-types/branded-03-impl.md index 1bcd6bee462b..469abe4b89a4 100644 --- a/src/idiomatic/leveraging-the-type-system/token-types/branded-03-impl.md +++ b/src/idiomatic/leveraging-the-type-system/token-types/branded-03-impl.md @@ -11,7 +11,7 @@ SPDX-License-Identifier: CC-BY-4.0 Constructing branded types is different to how we construct non-branded types. -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # @@ -37,10 +37,10 @@ impl<'id> Bytes<'id> { if ix < self.0.len() { Some(ProvenIndex(ix, InvariantLifetime::default())) } else { None } } - + fn get_proven(&self, ix: &ProvenIndex<'id>) -> u8 { debug_assert!(ix.0 < self.0.len()); - unsafe { *self.0.get_unchecked(ix.0) } + unsafe { *self.0.get_unchecked(ix.0) } } } ``` diff --git a/src/idiomatic/leveraging-the-type-system/typestate-pattern/typestate-generics/property.md b/src/idiomatic/leveraging-the-type-system/typestate-pattern/typestate-generics/property.md index 1290790898bd..9fd7560df16c 100644 --- a/src/idiomatic/leveraging-the-type-system/typestate-pattern/typestate-generics/property.md +++ b/src/idiomatic/leveraging-the-type-system/typestate-pattern/typestate-generics/property.md @@ -9,7 +9,7 @@ SPDX-License-Identifier: CC-BY-4.0 ## Serializer: implement Property -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/leveraging-the-type-system/typestate-pattern/typestate-generics/root.md b/src/idiomatic/leveraging-the-type-system/typestate-pattern/typestate-generics/root.md index 6411ce23842a..604d8580a235 100644 --- a/src/idiomatic/leveraging-the-type-system/typestate-pattern/typestate-generics/root.md +++ b/src/idiomatic/leveraging-the-type-system/typestate-pattern/typestate-generics/root.md @@ -9,7 +9,7 @@ SPDX-License-Identifier: CC-BY-4.0 ## Serializer: implement Root -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/leveraging-the-type-system/typestate-pattern/typestate-generics/struct.md b/src/idiomatic/leveraging-the-type-system/typestate-pattern/typestate-generics/struct.md index 6fc3f733e98c..d8f93bf7c47f 100644 --- a/src/idiomatic/leveraging-the-type-system/typestate-pattern/typestate-generics/struct.md +++ b/src/idiomatic/leveraging-the-type-system/typestate-pattern/typestate-generics/struct.md @@ -9,7 +9,7 @@ SPDX-License-Identifier: CC-BY-4.0 ## Serializer: implement Struct -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/polymorphism/from-oop-to-rust/composition.md b/src/idiomatic/polymorphism/from-oop-to-rust/composition.md index 95981edda3f3..c2263b1e0deb 100644 --- a/src/idiomatic/polymorphism/from-oop-to-rust/composition.md +++ b/src/idiomatic/polymorphism/from-oop-to-rust/composition.md @@ -9,7 +9,7 @@ SPDX-License-Identifier: CC-BY-4.0 # Composition over Inheritance -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/polymorphism/from-oop-to-rust/dynamic-dispatch/any-trait.md b/src/idiomatic/polymorphism/from-oop-to-rust/dynamic-dispatch/any-trait.md index 73ca28916771..e3a4bcc78f29 100644 --- a/src/idiomatic/polymorphism/from-oop-to-rust/dynamic-dispatch/any-trait.md +++ b/src/idiomatic/polymorphism/from-oop-to-rust/dynamic-dispatch/any-trait.md @@ -9,7 +9,7 @@ SPDX-License-Identifier: CC-BY-4.0 # Any Trait and Downcasting -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/polymorphism/from-oop-to-rust/dynamic-dispatch/dyn-compatible.md b/src/idiomatic/polymorphism/from-oop-to-rust/dynamic-dispatch/dyn-compatible.md index 6149f9b2f012..edc98b6f4670 100644 --- a/src/idiomatic/polymorphism/from-oop-to-rust/dynamic-dispatch/dyn-compatible.md +++ b/src/idiomatic/polymorphism/from-oop-to-rust/dynamic-dispatch/dyn-compatible.md @@ -9,7 +9,7 @@ SPDX-License-Identifier: CC-BY-4.0 # Dyn-compatible traits -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/polymorphism/from-oop-to-rust/dynamic-dispatch/dyn-trait.md b/src/idiomatic/polymorphism/from-oop-to-rust/dynamic-dispatch/dyn-trait.md index 02217e3e73a9..d978f3e22363 100644 --- a/src/idiomatic/polymorphism/from-oop-to-rust/dynamic-dispatch/dyn-trait.md +++ b/src/idiomatic/polymorphism/from-oop-to-rust/dynamic-dispatch/dyn-trait.md @@ -9,7 +9,7 @@ SPDX-License-Identifier: CC-BY-4.0 # `dyn Trait` for Dynamic Dispatch in Rust -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/polymorphism/from-oop-to-rust/dynamic-dispatch/dyn-vs-generics.md b/src/idiomatic/polymorphism/from-oop-to-rust/dynamic-dispatch/dyn-vs-generics.md index b11bfd3d00c6..e7115761b750 100644 --- a/src/idiomatic/polymorphism/from-oop-to-rust/dynamic-dispatch/dyn-vs-generics.md +++ b/src/idiomatic/polymorphism/from-oop-to-rust/dynamic-dispatch/dyn-vs-generics.md @@ -11,7 +11,7 @@ SPDX-License-Identifier: CC-BY-4.0 We have two means of writing polymorphic functions, how do they compare? -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/polymorphism/from-oop-to-rust/dynamic-dispatch/heterogeneous.md b/src/idiomatic/polymorphism/from-oop-to-rust/dynamic-dispatch/heterogeneous.md index 4d2e32ebe93d..0e163b902a28 100644 --- a/src/idiomatic/polymorphism/from-oop-to-rust/dynamic-dispatch/heterogeneous.md +++ b/src/idiomatic/polymorphism/from-oop-to-rust/dynamic-dispatch/heterogeneous.md @@ -9,7 +9,7 @@ SPDX-License-Identifier: CC-BY-4.0 # Heterogeneous data with `dyn trait` -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/polymorphism/from-oop-to-rust/dynamic-dispatch/limits.md b/src/idiomatic/polymorphism/from-oop-to-rust/dynamic-dispatch/limits.md index e55abdc9f2c7..52203db7db0e 100644 --- a/src/idiomatic/polymorphism/from-oop-to-rust/dynamic-dispatch/limits.md +++ b/src/idiomatic/polymorphism/from-oop-to-rust/dynamic-dispatch/limits.md @@ -9,7 +9,7 @@ SPDX-License-Identifier: CC-BY-4.0 # Limits of Trait Objects -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/polymorphism/from-oop-to-rust/dynamic-dispatch/pitfalls.md b/src/idiomatic/polymorphism/from-oop-to-rust/dynamic-dispatch/pitfalls.md index 6697b90aa61a..526a5335c683 100644 --- a/src/idiomatic/polymorphism/from-oop-to-rust/dynamic-dispatch/pitfalls.md +++ b/src/idiomatic/polymorphism/from-oop-to-rust/dynamic-dispatch/pitfalls.md @@ -9,7 +9,7 @@ SPDX-License-Identifier: CC-BY-4.0 # Pitfall: Reaching too quickly for `dyn Trait` -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/polymorphism/from-oop-to-rust/problem-solving.md b/src/idiomatic/polymorphism/from-oop-to-rust/problem-solving.md index cf10c2ea8232..bfb2d742611e 100644 --- a/src/idiomatic/polymorphism/from-oop-to-rust/problem-solving.md +++ b/src/idiomatic/polymorphism/from-oop-to-rust/problem-solving.md @@ -9,7 +9,7 @@ SPDX-License-Identifier: CC-BY-4.0 # Problem solving: Break Down the Problem -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/polymorphism/from-oop-to-rust/sealed-traits.md b/src/idiomatic/polymorphism/from-oop-to-rust/sealed-traits.md index c63cce153fbf..e041952369f5 100644 --- a/src/idiomatic/polymorphism/from-oop-to-rust/sealed-traits.md +++ b/src/idiomatic/polymorphism/from-oop-to-rust/sealed-traits.md @@ -9,7 +9,7 @@ SPDX-License-Identifier: CC-BY-4.0 # Sealed traits for Polymorphism users cannot extend -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/polymorphism/from-oop-to-rust/sealing-with-enums.md b/src/idiomatic/polymorphism/from-oop-to-rust/sealing-with-enums.md index 1bb0a0ff38e0..73baadef7345 100644 --- a/src/idiomatic/polymorphism/from-oop-to-rust/sealing-with-enums.md +++ b/src/idiomatic/polymorphism/from-oop-to-rust/sealing-with-enums.md @@ -9,7 +9,7 @@ SPDX-License-Identifier: CC-BY-4.0 # Sealing with Enums -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/polymorphism/from-oop-to-rust/sticking-with-traits.md b/src/idiomatic/polymorphism/from-oop-to-rust/sticking-with-traits.md index 8ca8dac286fc..bb4f55893115 100644 --- a/src/idiomatic/polymorphism/from-oop-to-rust/sticking-with-traits.md +++ b/src/idiomatic/polymorphism/from-oop-to-rust/sticking-with-traits.md @@ -9,7 +9,7 @@ SPDX-License-Identifier: CC-BY-4.0 # Traits for Polymorphism users can extend -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/polymorphism/from-oop-to-rust/supertraits.md b/src/idiomatic/polymorphism/from-oop-to-rust/supertraits.md index 4ec4d74ffed5..09a1b29339c8 100644 --- a/src/idiomatic/polymorphism/from-oop-to-rust/supertraits.md +++ b/src/idiomatic/polymorphism/from-oop-to-rust/supertraits.md @@ -9,7 +9,7 @@ SPDX-License-Identifier: CC-BY-4.0 # "Inheritance" in Rust: Supertraits -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/polymorphism/from-oop-to-rust/switch-perspective.md b/src/idiomatic/polymorphism/from-oop-to-rust/switch-perspective.md index c9a90bec325a..303c35170f2d 100644 --- a/src/idiomatic/polymorphism/from-oop-to-rust/switch-perspective.md +++ b/src/idiomatic/polymorphism/from-oop-to-rust/switch-perspective.md @@ -9,7 +9,7 @@ SPDX-License-Identifier: CC-BY-4.0 # Inheritance from Rust's Perspective -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/polymorphism/from-oop-to-rust/why-no-inheritance.md b/src/idiomatic/polymorphism/from-oop-to-rust/why-no-inheritance.md index da3d4d39aa71..a26d9510a707 100644 --- a/src/idiomatic/polymorphism/from-oop-to-rust/why-no-inheritance.md +++ b/src/idiomatic/polymorphism/from-oop-to-rust/why-no-inheritance.md @@ -9,7 +9,7 @@ SPDX-License-Identifier: CC-BY-4.0 # Why no Inheritance in Rust? -```rust,compile_fail +```rust,editable,compile_fail # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/polymorphism/refresher/blanket-impls.md b/src/idiomatic/polymorphism/refresher/blanket-impls.md index 66c710b47e68..aa2b7cad39ee 100644 --- a/src/idiomatic/polymorphism/refresher/blanket-impls.md +++ b/src/idiomatic/polymorphism/refresher/blanket-impls.md @@ -12,7 +12,7 @@ SPDX-License-Identifier: CC-BY-4.0 When a trait is local, we can implement it for as many types as we like. How far can we take this? -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/polymorphism/refresher/conditional-methods.md b/src/idiomatic/polymorphism/refresher/conditional-methods.md index e08293f23b19..35d366f51e9a 100644 --- a/src/idiomatic/polymorphism/refresher/conditional-methods.md +++ b/src/idiomatic/polymorphism/refresher/conditional-methods.md @@ -9,7 +9,7 @@ SPDX-License-Identifier: CC-BY-4.0 # Conditional Method Implementations -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/polymorphism/refresher/default-impls.md b/src/idiomatic/polymorphism/refresher/default-impls.md index 28f1a5520565..3d966bb94dd0 100644 --- a/src/idiomatic/polymorphism/refresher/default-impls.md +++ b/src/idiomatic/polymorphism/refresher/default-impls.md @@ -9,7 +9,7 @@ SPDX-License-Identifier: CC-BY-4.0 # Default Method Implementations -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/polymorphism/refresher/deriving-traits.md b/src/idiomatic/polymorphism/refresher/deriving-traits.md index 6357c0226eb8..f97e6bc28a1e 100644 --- a/src/idiomatic/polymorphism/refresher/deriving-traits.md +++ b/src/idiomatic/polymorphism/refresher/deriving-traits.md @@ -9,7 +9,7 @@ SPDX-License-Identifier: CC-BY-4.0 # Deriving Traits -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/polymorphism/refresher/monomorphization.md b/src/idiomatic/polymorphism/refresher/monomorphization.md index c78dfdc07b18..090e96d0bdf1 100644 --- a/src/idiomatic/polymorphism/refresher/monomorphization.md +++ b/src/idiomatic/polymorphism/refresher/monomorphization.md @@ -9,7 +9,7 @@ SPDX-License-Identifier: CC-BY-4.0 # Monomorphization and Binary Size -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/polymorphism/refresher/orphan-rule.md b/src/idiomatic/polymorphism/refresher/orphan-rule.md index 59d35e86747e..eed8feb55748 100644 --- a/src/idiomatic/polymorphism/refresher/orphan-rule.md +++ b/src/idiomatic/polymorphism/refresher/orphan-rule.md @@ -11,7 +11,7 @@ SPDX-License-Identifier: CC-BY-4.0 What prevents users from writing arbitrary trait implementations for any type? -```rust,compile_fail +```rust,editable,compile_fail # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/polymorphism/refresher/sized.md b/src/idiomatic/polymorphism/refresher/sized.md index ea1cf2885075..83fd3a9ad2eb 100644 --- a/src/idiomatic/polymorphism/refresher/sized.md +++ b/src/idiomatic/polymorphism/refresher/sized.md @@ -9,7 +9,7 @@ SPDX-License-Identifier: CC-BY-4.0 # Statically Sized and Dynamically Sized Types -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/polymorphism/refresher/supertraits.md b/src/idiomatic/polymorphism/refresher/supertraits.md index 323d23a8bc0e..258c1f8c58ff 100644 --- a/src/idiomatic/polymorphism/refresher/supertraits.md +++ b/src/idiomatic/polymorphism/refresher/supertraits.md @@ -11,7 +11,7 @@ SPDX-License-Identifier: CC-BY-4.0 Traits can be extended by new traits. -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/polymorphism/refresher/trait-bounds.md b/src/idiomatic/polymorphism/refresher/trait-bounds.md index 19e0322b6979..73b26e894ec7 100644 --- a/src/idiomatic/polymorphism/refresher/trait-bounds.md +++ b/src/idiomatic/polymorphism/refresher/trait-bounds.md @@ -9,7 +9,7 @@ SPDX-License-Identifier: CC-BY-4.0 # Trait Bounds on Generics -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 # diff --git a/src/idiomatic/polymorphism/refresher/traits.md b/src/idiomatic/polymorphism/refresher/traits.md index 7ca612b6e5a4..25061a6840f2 100644 --- a/src/idiomatic/polymorphism/refresher/traits.md +++ b/src/idiomatic/polymorphism/refresher/traits.md @@ -9,7 +9,7 @@ SPDX-License-Identifier: CC-BY-4.0 # Traits, Protocols, Interfaces -```rust +```rust,editable # // Copyright 2025 Google LLC # // SPDX-License-Identifier: Apache-2.0 #