Skip to content

Commit 1c358b1

Browse files
committed
Remove the cast dependency.
It was only used between usize and u64 in parts of the code that were marked with `#[cfg(target_pointer_width = "64")]`, which guarantees usize is 64 bits.
1 parent 0334cbc commit 1c358b1

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,5 @@ edition = "2018"
2929
bit_field = "0.9.0"
3030
bitflags = "1.0.4"
3131

32-
[dependencies.cast]
33-
version = "0.2.2"
34-
default-features = false
35-
3632
[features]
3733
deny-warnings = []

src/addr.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ impl VirtAddr {
8989

9090
/// Creates a virtual address from the given pointer
9191
pub fn from_ptr<T>(ptr: *const T) -> Self {
92-
Self::new(cast::u64(ptr as usize))
92+
Self::new(ptr as u64)
9393
}
9494

9595
/// Converts the address to a raw pointer.
9696
#[cfg(target_pointer_width = "64")]
9797
pub fn as_ptr<T>(self) -> *const T {
98-
cast::usize(self.as_u64()) as *const T
98+
self.as_u64() as *const T
9999
}
100100

101101
/// Converts the address to a mutable raw pointer.
@@ -181,14 +181,14 @@ impl AddAssign<u64> for VirtAddr {
181181
impl Add<usize> for VirtAddr {
182182
type Output = Self;
183183
fn add(self, rhs: usize) -> Self::Output {
184-
self + cast::u64(rhs)
184+
self + rhs as u64
185185
}
186186
}
187187

188188
#[cfg(target_pointer_width = "64")]
189189
impl AddAssign<usize> for VirtAddr {
190190
fn add_assign(&mut self, rhs: usize) {
191-
self.add_assign(cast::u64(rhs))
191+
self.add_assign(rhs as u64)
192192
}
193193
}
194194

@@ -209,14 +209,14 @@ impl SubAssign<u64> for VirtAddr {
209209
impl Sub<usize> for VirtAddr {
210210
type Output = Self;
211211
fn sub(self, rhs: usize) -> Self::Output {
212-
self - cast::u64(rhs)
212+
self - rhs as u64
213213
}
214214
}
215215

216216
#[cfg(target_pointer_width = "64")]
217217
impl SubAssign<usize> for VirtAddr {
218218
fn sub_assign(&mut self, rhs: usize) {
219-
self.sub_assign(cast::u64(rhs))
219+
self.sub_assign(rhs as u64)
220220
}
221221
}
222222

@@ -347,14 +347,14 @@ impl AddAssign<u64> for PhysAddr {
347347
impl Add<usize> for PhysAddr {
348348
type Output = Self;
349349
fn add(self, rhs: usize) -> Self::Output {
350-
self + cast::u64(rhs)
350+
self + rhs as u64
351351
}
352352
}
353353

354354
#[cfg(target_pointer_width = "64")]
355355
impl AddAssign<usize> for PhysAddr {
356356
fn add_assign(&mut self, rhs: usize) {
357-
self.add_assign(cast::u64(rhs))
357+
self.add_assign(rhs as u64)
358358
}
359359
}
360360

@@ -375,14 +375,14 @@ impl SubAssign<u64> for PhysAddr {
375375
impl Sub<usize> for PhysAddr {
376376
type Output = Self;
377377
fn sub(self, rhs: usize) -> Self::Output {
378-
self - cast::u64(rhs)
378+
self - rhs as u64
379379
}
380380
}
381381

382382
#[cfg(target_pointer_width = "64")]
383383
impl SubAssign<usize> for PhysAddr {
384384
fn sub_assign(&mut self, rhs: usize) {
385-
self.sub_assign(cast::u64(rhs))
385+
self.sub_assign(rhs as u64)
386386
}
387387
}
388388

0 commit comments

Comments
 (0)