ratatui_toolkit/widgets/code_diff/foundation/diff_line/constructors/
new.rs

1use crate::widgets::code_diff::diff_line::DiffLine;
2use crate::widgets::code_diff::enums::DiffLineKind;
3
4impl DiffLine {
5    /// Creates a new diff line with all fields specified.
6    ///
7    /// # Arguments
8    ///
9    /// * `kind` - The type of diff line
10    /// * `content` - The text content of the line
11    /// * `old_line_num` - Line number in the old version (None for added lines)
12    /// * `new_line_num` - Line number in the new version (None for removed lines)
13    ///
14    /// # Returns
15    ///
16    /// A new `DiffLine` instance
17    ///
18    /// # Example
19    ///
20    /// ```rust
21    /// use ratatui_toolkit::code_diff::{DiffLine, DiffLineKind};
22    ///
23    /// let line = DiffLine::new(
24    ///     DiffLineKind::Context,
25    ///     "unchanged line",
26    ///     Some(10),
27    ///     Some(12),
28    /// );
29    /// ```
30    pub fn new(
31        kind: DiffLineKind,
32        content: impl Into<String>,
33        old_line_num: Option<usize>,
34        new_line_num: Option<usize>,
35    ) -> Self {
36        Self {
37            kind,
38            content: content.into(),
39            old_line_num,
40            new_line_num,
41        }
42    }
43}