Use a much more sensible method naming for SocketRef.
parent
103fff9233
commit
d37f4ef254
|
@ -108,8 +108,8 @@ macro_rules! from_socket {
|
|||
impl<'a, 'b> AnySocket<'a, 'b> for $socket {
|
||||
fn downcast<'c>(ref_: SocketRef<'c, Socket<'a, 'b>>) ->
|
||||
Option<SocketRef<'c, Self>> {
|
||||
match SocketRef::unwrap(ref_) {
|
||||
&mut Socket::$variant(ref mut socket) => Some(SocketRef::wrap(socket)),
|
||||
match SocketRef::into_inner(ref_) {
|
||||
&mut Socket::$variant(ref mut socket) => Some(SocketRef::new(socket)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,10 +35,10 @@ pub struct Ref<'a, T: Session + 'a> {
|
|||
impl<'a, T: Session + 'a> Ref<'a, T> {
|
||||
/// Wrap a pointer to a socket to make a smart pointer.
|
||||
///
|
||||
/// Calling this function is only necessary if your code is using [unwrap].
|
||||
/// Calling this function is only necessary if your code is using [into_inner].
|
||||
///
|
||||
/// [unwrap]: #method.unwrap
|
||||
pub fn wrap(socket: &'a mut T) -> Self {
|
||||
/// [into_inner]: #method.into_inner
|
||||
pub fn new(socket: &'a mut T) -> Self {
|
||||
Ref { socket, consumed: false }
|
||||
}
|
||||
|
||||
|
@ -49,10 +49,10 @@ impl<'a, T: Session + 'a> Ref<'a, T> {
|
|||
///
|
||||
/// Calling this function is only necessary to achieve composability if you *must*
|
||||
/// map a `&mut SocketRef<'a, XSocket>` to a `&'a mut XSocket` (note the lifetimes);
|
||||
/// be sure to call [wrap] afterwards.
|
||||
/// be sure to call [new] afterwards.
|
||||
///
|
||||
/// [wrap]: #method.wrap
|
||||
pub fn unwrap(mut ref_: Self) -> &'a mut T {
|
||||
/// [new]: #method.new
|
||||
pub fn into_inner(mut ref_: Self) -> &'a mut T {
|
||||
ref_.consumed = true;
|
||||
ref_.socket
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ impl<'a, 'b: 'a, 'c: 'a + 'b> Set<'a, 'b, 'c> {
|
|||
pub fn get<T: AnySocket<'b, 'c>>(&mut self, handle: Handle) -> SocketRef<T> {
|
||||
match self.sockets[handle.0].as_mut() {
|
||||
Some(item) => {
|
||||
T::downcast(SocketRef::wrap(&mut item.socket))
|
||||
T::downcast(SocketRef::new(&mut item.socket))
|
||||
.expect("handle refers to a socket of a wrong type")
|
||||
}
|
||||
None => panic!("handle does not refer to a valid socket")
|
||||
|
@ -209,7 +209,7 @@ impl<'a, 'b: 'a, 'c: 'a + 'b> Iterator for IterMut<'a, 'b, 'c> {
|
|||
fn next(&mut self) -> Option<Self::Item> {
|
||||
while let Some(item_opt) = self.lower.next() {
|
||||
if let Some(item) = item_opt.as_mut() {
|
||||
return Some(SocketRef::wrap(&mut item.socket))
|
||||
return Some(SocketRef::new(&mut item.socket))
|
||||
}
|
||||
}
|
||||
None
|
||||
|
|
Loading…
Reference in New Issue