Repository: Spotifyd/spotifyd (language: rust)

Issue:
Error "use of unstable library feature" while building
**Description**
While compiling using cargo from latest master, error occurs: use of unstable library feature 'bool_to_option' in **src/config.rs:636:57**.
This error occurs in lastly changed lines: 00f52f983ce0d2162ea2fef677e2c9eee7c8f6ef

**To Reproduce**
1. sudo apt install rustc cargo libasound2-dev libssl-dev pkg-config
2. git clone https://github.com/Spotifyd/spotifyd.git
3. cd spotifyd
4. cargo build --release <- ERROR

**Expected behavior**
It should compile

**Logs**
<details><summary>Click to show logs</summary>

```
xxx@xxx:~/projects/spotifyd$ cargo build --release 
   Compiling spotifyd v0.3.3 (/home/xxx/spotifyd)
error[E0658]: use of unstable library feature 'bool_to_option'
   --> src/config.rs:636:57
    |
636 |         .map(|path| Cache::new(Some(&path), audio_cache.then_some(&path), size_limit))
    |                                                         ^^^^^^^^^
    |
    = note: see issue #80967 <https://github.com/rust-lang/rust/issues/80967> for more information

For more information about this error, try `rustc --explain E0658`.
error: could not compile `spotifyd` due to previous error

```
</details>


**Compilation flags** 
- [ ] dbus_mpris
- [ ] dbus_keyring
- [x] alsa_backend
- [ ] portaudio_backend
- [ ] pulseaudio_backend
- [ ] rodio_backend

**Versions (please complete the following information):**
<!-- DO NOT use words like `latest`. Please specify the exact version/commit hash -->
- OS: Ubuntu 20.04.5 LTS
- Spotifyd: 00f52f983ce0d2162ea2fef677e2c9eee7c8f6ef
- cargo: 1.61.0




Discussion / hints:
Hi and thank you for the report!

The problematic `then_some` has been stabilized in Rust 1.62.0 (the latest is 1.64.0), so in order to compile this version, you'd need to use a different distribution channel (e.g. [`rustup`](https://rustup.rs/)).

---

In general, I'm not sure what a good way forward would be on this one? I don't think there are any guarantees about a minimum rust version that is supported, and, since the main distribution channel is probably through GitHub releases, it shouldn't cause much breakage either to “live on the edge”.

In this case, though, the benefit of using the feature is minor and could be easily reverted. Given that there have already been two users that stumbled upon this independently of each other, it might be worth changing that line. Alternatives would be:

```rust
audio_cache.then_some(&path) // current
Some(&path).filter(|_| audio_cache) // alternative
if audio_cache { Some(&path) } else { None } // previous solution
```

(A bit more verbose, but overall not much worse.)

So I'm not entirely sure what to do. @Spotifyd/maintainers, any opinions on this?
Me too
same issue here
> The problematic `then_some` has been stabilized in Rust 1.62.0 (the latest is 1.64.0), so in order to compile this version, you'd need to use a different distribution channel (e.g. [`rustup`](https://rustup.rs/)).

Thanks for reply, changing **rustc** to **rustup** solved compilation problem and everything works well. 
To avoid situations like this, I would recommend to change [ubuntu instalation guide](https://spotifyd.github.io/spotifyd/installation/Ubuntu.html) on wiki. It will help a lot for new users like me ;) 


> > The problematic `then_some` has been stabilized in Rust 1.62.0 (the latest is 1.64.0), so in order to compile this version, you'd need to use a different distribution channel (e.g. [`rustup`](https://rustup.rs/)).
> 
> Thanks for reply, changing **rustc** to **rustup** solved compilation problem and everything works well. To avoid situations like this, I would recommend to change [ubuntu instalation guide](https://spotifyd.github.io/spotifyd/installation/Ubuntu.html) on wiki. It will help a lot for new users like me ;)

So can you explain how to change to rustup to 1.6.2 ? I dont know rust so much
> So can you explain how to change to rustup to 1.6.2 ? I dont know rust so much

It was my first contact with rust ever. I just uninstalled rustc and installed rustup instead using apt. Everything worked out of the box.
In Ubuntu 22.04.LTS
sudo apt install rustup 
returns No apt package "rustup", but there is a snap with that name.
With snap the user is  warned that it has security vulnerabilities.

@KidElectric just google "rustup install" and the first link will give you [answer](https://www.rust-lang.org/tools/install) 
Remove rustc
`sudo apt remove rustc`
and then install rustup
`curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh`
and then restart shell, now you can compile spotifyd with
`cargo build --release`
Considering how many users fail to get spotifyd up and running due to this change, I'm gonna revert this for now. Maybe we can come up with a policy at some point on how to handle such things in general.
I'm actually surprised that there's many people out there using outdated Rust versions trying to compile Rust projects from source...I've seen criticism of this phenomena in the past, but the Rust ecosystem has a tendency to move quickly to new versions.

If we wanted to establish a policy for when we use features from newer versions in source code, my first suggestion would be using when Gentoo moves the version from 'testing' to 'stable', which currently means the newest targetable Rust version is 1.62.1. Plenty of distros (including the one I use) package even newer versions than that, so it seems a reasonable fallback.

In a related sense, we definitely should not be recommending that users of distros which ship very outdated versions of Rust use their distro's Rust version to compile — this bodes for pretty much every open-source project, but especially so for Rust projects where devs are almost universally using `rustup`. I agree with @kristopalka that we should change our installation instructions for Ubuntu to account for that.
That sounds very reasonable! It's almost always better to fix the underlying problem rather than the symptoms.

I guess I'll thus refrain from reverting that change, and instead we can try to quickly change the installation instructions in the book? Or should I still add a quick fix for the current issue?

Fix patch:
diff --git a/docs/src/installation/Ubuntu.md b/docs/src/installation/Ubuntu.md
index d9b615bd..93e3cdd7 100644
--- a/docs/src/installation/Ubuntu.md
+++ b/docs/src/installation/Ubuntu.md
@@ -1,9 +1,16 @@
 # Ubuntu install guide
 
+## Install the rust toolchain
+
+To install the latest rust toolchain, follow the installation instructions on [rustup.rs][rustup].
+
+> **Note:** If you installed rust before via apt, you need to remove it before installing rustup.
+> We recommend to always use the latest version and don't guarantee compatibility with older ones.
+
 ## Install the requirements
 
 ```bash
-sudo apt install rustc cargo libasound2-dev libssl-dev pkg-config
+sudo apt install libasound2-dev libssl-dev pkg-config
 ```
 
 ## Clone the repository
@@ -26,3 +33,5 @@ The resulting binary will be placed in `target/release/spotifyd`
 ## Running spotifyd
 
 You can run it using `./target/release/spotifyd`
+
+[rustup]: https://rustup.rs/


Test patch: