Skip Navigation
InitialsDiceBearhttps://github.com/dicebear/dicebearhttps://creativecommons.org/publicdomain/zero/1.0/„Initials” (https://github.com/dicebear/dicebear) by „DiceBear”, licensed under „CC0 1.0” (https://creativecommons.org/publicdomain/zero/1.0/)SI
silva @sopuli.xyz
Posts 4
Comments 13

Allow argument in macro to be Option<T> or T

Hey,

Is there any way to create a macro that allows a Some<T> or T as input?

It's for creating a Span struct that I'm using:

rust struct Span { line: usize, column: usize, file_path: Option<String>, }

...and I have the following macro:

```rust macro_rules! span { ($line:expr, $column:expr) => { Span { line: $line, column: $column file_path: None, } };

($line:expr, $column:expr, $file_path: expr) => { Span { line: $line, column: $column file_path: Some($file_path.to_string()), } }; } ```

...which allows me to do this:

rust let foo = span!(1, 1); let bar = span!(1, 1, "file.txt");

However, sometimes I don't want to pass in the file path directly but through a variable that is Option<String>. To do this, I always have to match the variable:

```rust let file_path = Some("file.txt");

let foo = match file_path { Some(file_path) => span!(1, 1, file_path), None => span!(1, 1), } ```

Is there a way which allows me to directly use span!(1, 1, file_path) where file_path could be "file.txt", Some("file.txt") or None?

Thanks in advance!

15

Free Kiosk App

Hey, Do you know any free kiosk apps (an app that only allow you to use one app) like Fully Single Kiosk App?

3
Why Do You Pirate Music?
  • I've also had issues with Lidarr not downloading anything - For example, I tried downloading music from the artist NF - which I don't think is a particularly niche artist - but Lidarr didn't download anything. What indexers do you use to download music?

  • Rule
  • I know, it was exactly the same for me. I hated it when people didn't tell me anything about the game and just said 'Play It'.

    Then I bought it anyway during a sale, and now I'm one of those people: Play It. Without any spoilers.