on master help sign in
Mark a few functions as `const`
cee7ad7Blaž Hrastnik
helix-core/src/line_ending.rs+3−3
@@ -20,7 +20,7 @@ pub enum LineEnding {
20
20
21impl LineEnding {
21impl LineEnding {
22 #[inline]
22 #[inline]
23− pub fn len_chars(&self) -> usize {
23+ pub const fn len_chars(&self) -> usize {
24 match self {
24 match self {
25 Self::Crlf => 2,
25 Self::Crlf => 2,
26 _ => 1,
26 _ => 1,
@@ -28,7 +28,7 @@ impl LineEnding {
28 }
28 }
29
29
30 #[inline]
30 #[inline]
31− pub fn as_str(&self) -> &'static str {
31+ pub const fn as_str(&self) -> &'static str {
32 match self {
32 match self {
33 Self::Crlf => "\u{000D}\u{000A}",
33 Self::Crlf => "\u{000D}\u{000A}",
34 Self::LF => "\u{000A}",
34 Self::LF => "\u{000A}",
@@ -42,7 +42,7 @@ impl LineEnding {
42 }
42 }
43
43
44 #[inline]
44 #[inline]
45− pub fn from_char(ch: char) -> Option<LineEnding> {
45+ pub const fn from_char(ch: char) -> Option<LineEnding> {
46 match ch {
46 match ch {
47 '\u{000A}' => Some(LineEnding::LF),
47 '\u{000A}' => Some(LineEnding::LF),
48 '\u{000B}' => Some(LineEnding::VT),
48 '\u{000B}' => Some(LineEnding::VT),
helix-core/src/register.rs+2−2
@@ -7,7 +7,7 @@ pub struct Register {
7}
7}
8
8
9impl Register {
9impl Register {
10− pub fn new(name: char) -> Self {
10+ pub const fn new(name: char) -> Self {
11 Self {
11 Self {
12 name,
12 name,
13 values: Vec::new(),
13 values: Vec::new(),
@@ -18,7 +18,7 @@ impl Register {
18 Self { name, values }
18 Self { name, values }
19 }
19 }
20
20
21− pub fn name(&self) -> char {
21+ pub const fn name(&self) -> char {
22 self.name
22 self.name
23 }
23 }
24
24
helix-term/src/ui/editor.rs+1−1
@@ -1106,7 +1106,7 @@ fn canonicalize_key(key: &mut KeyEvent) {
1106}
1106}
1107
1107
1108#[inline]
1108#[inline]
1109−fn abs_diff(a: usize, b: usize) -> usize {
1109+const fn abs_diff(a: usize, b: usize) -> usize {
1110 if a > b {
1110 if a > b {
1111 a - b
1111 a - b
1112 } else {
1112 } else {