Skip to main content

with_default

Function with_default 

Source
pub fn with_default(text: &str, mime: &str, app: &str) -> String
Expand description

text with mime set to open in app — the whole file back, one line different.

Three cases, in the order they are met in the wild:

  • The type already has a line: that line’s value is replaced, where it sits. Moving it to the bottom would reorder a file someone grouped on purpose.
  • There is a [Default Applications] section but no line for this type: the line is added at the end of that section, before any blank line that separates it from the next one.
  • There is no such section: it is appended, after a blank line.

The file’s own line endings are not preserved, because every writer of this format uses \n and pretending otherwise would mean carrying a guess through every branch above.