The problem is that if i % 3 == 0 { "Fizz" }
returns either unit ()
or &'static str
. Change the if expressions to return the same type in both cases, for example by adding a else { "" }
.
More Related Contents:
- Why do I need to import a trait to use the methods it defines for a type?
- Why does linking lifetimes matter only with mutable references?
- Why is adding a lifetime to a trait with the plus operator (Iterator + ‘a) needed?
- Should trait bounds be duplicated in struct and impl?
- Can I do type introspection with trait objects and then downcast it?
- How can I perform parallel asynchronous HTTP GET requests with reqwest?
- Convert a String to int?
- How do I borrow a RefCell, find a key, and return a reference to the result? [duplicate]
- How can I store a Chars iterator in the same struct as the String it is iterating on?
- How to disable unused code warnings in Rust?
- Is there a way other than traits to add methods to a type I don’t own?
- Trait implementation for both a trait object and for direct implementors of the trait
- Can’t borrow mutably within two different closures in the same scope
- What is the syntax to match on a reference to an enum?
- How can I implement Rust’s Copy trait?
- How to iterate over and filter an array?
- How to use a struct’s member as its own key when inserting the struct into a map without duplicating it?
- Is there another option to share an Arc in multiple closures besides cloning it before each closure?
- How to implement a custom ‘fmt::Debug’ trait?
- How do I pass a closure through raw pointers as an argument to a C function?
- Is there a way to use existing structs as enum variants?
- What is the prelude?
- How do I use a crate from another crate without explicitly defining a new dependency in my project?
- How do I print an integer in binary with leading zeros?
- What does Rust’s unary || (parallel pipe) mean?
- How to create and write to memory mapped files?
- Downcast traits inside Rc for AST manipulation
- Why does Valgrind not detect a memory leak in a Rust program using nightly 1.29.0?
- How to check in Rust if architecture is 32 or 64 bit?
- What is the null pointer optimization in Rust?