Skip to content

Commit

Permalink
Merge pull request #137 from dtolnay/cast
Browse files Browse the repository at this point in the history
Force turbofish on all calls of .cast::<U>()
  • Loading branch information
dtolnay committed Jan 30, 2021
2 parents 3723acd + 3fdef75 commit 3626541
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl<T> Own<T> {
}
}

pub fn cast<U>(self) -> Own<U> {
pub fn cast<U: CastTo>(self) -> Own<U::Target> {
Own {
ptr: self.ptr.cast(),
}
Expand Down Expand Up @@ -69,7 +69,7 @@ impl<'a, T> Ref<'a, T> {
}
}

pub fn cast<U>(self) -> Ref<'a, U> {
pub fn cast<U: CastTo>(self) -> Ref<'a, U::Target> {
Ref {
ptr: self.ptr.cast(),
lifetime: PhantomData,
Expand Down Expand Up @@ -102,7 +102,7 @@ impl<'a, T> Mut<'a, T> {
}
}

pub fn cast<U>(self) -> Mut<'a, U> {
pub fn cast<U: CastTo>(self) -> Mut<'a, U::Target> {
Mut {
ptr: self.ptr.cast(),
lifetime: PhantomData,
Expand All @@ -124,3 +124,12 @@ impl<'a, T> Mut<'a, T> {
self.ptr.as_ptr().read()
}
}

// Force turbofish on all calls of `.cast::<U>()`.
pub trait CastTo {
type Target;
}

impl<T> CastTo for T {
type Target = T;
}

0 comments on commit 3626541

Please sign in to comment.