• xor
    link
    English
    117 months ago

    The original example was doing the unwrap_within an iterator doing some string parsing, so there was a lot of unrelated boilerplate around the actual unwrapping that made it really unclear, as well as usual unwrap_or_else to produce a constant value

    Ehhh, I was more using get_default as a placeholder for some function, as opposed to representing Default::default for the inner type specifically. I think it should be alright since only people familiar with rust would know about the default trait anyway. I did consider adding an unwrap_or_default example, but thought it was getting a bit off topic at that point.

      • xor
        link
        English
        17 months ago

        Ayyyyy

    • @barsoap@lemm.ee
      link
      fedilink
      17 months ago

      Maybe shouldn’t call the function anything default and also provide it. The std docs say:

      fn count(x: &str) -> usize { x.len() }
      
      assert_eq!(Ok(2).unwrap_or_else(count), 2);
      assert_eq!(Err("foo").unwrap_or_else(count), 3);