1 Inner items do not inherit type or const parameters from the functions
4 Erroneous code example:
8 fn bar(y: T) { // T is defined in the "outer" function
19 type MaybeT = Option<T>;
35 Items inside functions are basically just like top-level items, except
36 that they can only be used from the function they are in.
38 There are a couple of solutions for this.
40 If the item is a function, you may use a closure:
44 let bar = |y: T| { // explicit type annotation may not be necessary
51 For a generic item, you can copy over the parameters:
64 type MaybeT<T> = Option<T>;
68 Be sure to copy over any bounds as well:
71 fn foo<T: Copy>(x: T) {
72 fn bar<T: Copy>(y: T) {
80 fn foo<T: Copy>(x: T) {
87 This may require additional type hints in the function body.
89 In case the item is a function inside an `impl`, defining a private helper
90 function might be easier:
95 pub fn foo(&self, x: T) {
105 For default impls in traits, the private helper solution won't work, however
106 closures or copying the parameters should still work.