Skip to content

Commit fa5dac4

Browse files
committed
Implements Deref on EfiString
1 parent cfd6f2f commit fa5dac4

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/string.rs

+16-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use alloc::vec::Vec;
33
use core::borrow::Borrow;
44
use core::fmt::{Formatter, Write};
55
use core::mem::transmute;
6+
use core::ops::Deref;
67
use core::slice::{from_raw_parts, IterMut};
78
use core::str::FromStr;
89

@@ -163,9 +164,23 @@ impl FromStr for EfiString {
163164
}
164165
}
165166

167+
impl Deref for EfiString {
168+
type Target = EfiStr;
169+
170+
fn deref(&self) -> &Self::Target {
171+
unsafe { EfiStr::new_unchecked(&self.0) }
172+
}
173+
}
174+
166175
impl AsRef<EfiStr> for EfiString {
167176
fn as_ref(&self) -> &EfiStr {
168-
self.borrow()
177+
self.deref()
178+
}
179+
}
180+
181+
impl Borrow<EfiStr> for EfiString {
182+
fn borrow(&self) -> &EfiStr {
183+
self.deref()
169184
}
170185
}
171186

@@ -181,12 +196,6 @@ impl<'a> IntoIterator for &'a mut EfiString {
181196
}
182197
}
183198

184-
impl Borrow<EfiStr> for EfiString {
185-
fn borrow(&self) -> &EfiStr {
186-
unsafe { EfiStr::new_unchecked(&self.0) }
187-
}
188-
}
189-
190199
/// A non-NUL character in the EFI string.
191200
#[repr(transparent)]
192201
pub struct EfiChar(u16);

0 commit comments

Comments
 (0)