Skip to content

Commit a818c27

Browse files
committed
Implementing From for foreign types is actually possible
The new orphan rules allow this. Since `Into<T>` has a blanked impl for `From<T>`, but not the other way around, it is recommended to always implement `From` if possible.
1 parent 2ac0c82 commit a818c27

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/boot_info.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ impl From<&'static mut [MemoryRegion]> for MemoryRegions {
9696
}
9797
}
9898

99-
impl Into<&'static mut [MemoryRegion]> for MemoryRegions {
100-
fn into(self) -> &'static mut [MemoryRegion] {
101-
unsafe { slice::from_raw_parts_mut(self.ptr, self.len) }
99+
impl From<MemoryRegions> for &'static mut [MemoryRegion] {
100+
fn from(regions: MemoryRegions) -> &'static mut [MemoryRegion] {
101+
unsafe { slice::from_raw_parts_mut(regions.ptr, regions.len) }
102102
}
103103
}
104104

@@ -248,9 +248,9 @@ impl<T> From<Option<T>> for Optional<T> {
248248
}
249249
}
250250

251-
impl<T> Into<Option<T>> for Optional<T> {
252-
fn into(self) -> Option<T> {
253-
match self {
251+
impl<T> From<Optional<T>> for Option<T> {
252+
fn from(optional: Optional<T>) -> Option<T> {
253+
match optional {
254254
Optional::Some(v) => Some(v),
255255
Optional::None => None,
256256
}

0 commit comments

Comments
 (0)