Function first_line

Source
pub fn first_line(text: &str, with_ellipses: bool) -> Cow<'_, str>
Expand description

Returns the first line in text, up to the first \n if the text contains multiple lines, and optionally adds ellipses “…” to the end of the line if with_ellipses is true.

If the text is a single-line string, returns the original text.

Suitable for showing just the first line of a piece of code. E.g., if text is: if x { 0 } else { 1 } the returned value, with ellipses, will be: if x {…