git.delta.rocks / jrsonnet / refs/commits / 34a152fcae11

difftreelog

feat(interner) make more functions const

Yaroslav Bolyukin2022-07-23parent: #5a21a2e.patch.diff
in: master

2 files changed

modifiedcrates/jrsonnet-interner/src/inner.rsdiffbeforeafterboth
84 unsafe { Self::new_raw(str.as_bytes(), true) }84 unsafe { Self::new_raw(str.as_bytes(), true) }
85 }85 }
8686
87 pub fn as_slice(&self) -> &[u8] {87 pub const fn as_slice(&self) -> &[u8] {
88 let header = Self::header(self);88 let header = Self::header(self);
89 // SAFETY: data is not null, and it is correctly initialized89 // SAFETY: data is not null, and it is correctly initialized
90 let size = unsafe { (*header).size };90 let size = unsafe { (*header).size };
9999
100 /// # Safety100 /// # Safety
101 /// Data should be checked to be utf8 via [`check_utf8`] first101 /// Data should be checked to be utf8 via [`check_utf8`] first
102 pub unsafe fn as_str_unchecked(&self) -> &str {102 pub const unsafe fn as_str_unchecked(&self) -> &str {
103 // SAFETY: data is checked103 // SAFETY: data is checked
104 unsafe { str::from_utf8_unchecked(self.as_slice()) }104 unsafe { str::from_utf8_unchecked(self.as_slice()) }
105 }105 }
modifiedcrates/jrsonnet-interner/src/lib.rsdiffbeforeafterboth
129 }129 }
130130
131 #[must_use]131 #[must_use]
132 pub fn as_slice(&self) -> &[u8] {132 pub const fn as_slice(&self) -> &[u8] {
133 self.0.as_slice()133 self.0.as_slice()
134 }134 }
135}135}