Trait nom::lib::std::prelude::v1::rust_2015::AsRef1.0.0[][src]

pub trait AsRef<T> where
    T: ?Sized
{ pub fn as_ref(&self) -> &T; }
[]

Used to do a cheap reference-to-reference conversion.

This trait is similar to AsMut which is used for converting between mutable references. If you need to do a costly conversion it is better to implement From with type &T or write a custom function.

AsRef has the same signature as Borrow, but Borrow is different in few aspects:

Note: This trait must not fail. If the conversion can fail, use a dedicated method which returns an Option<T> or a Result<T, E>.

Generic Implementations

Examples

By using trait bounds we can accept arguments of different types as long as they can be converted to the specified type T.

For example: By creating a generic function that takes an AsRef<str> we express that we want to accept all references that can be converted to &str as an argument. Since both String and &str implement AsRef<str> we can accept both as input argument.

fn is_hello<T: AsRef<str>>(s: T) {
   assert_eq!("hello", s.as_ref());
}

let s = "hello";
is_hello(s);

let s = "hello".to_string();
is_hello(s);

Required methods

pub fn as_ref(&self) -> &T[src][]

Performs the conversion.

Implementors

impl AsRef<[u8]> for str[src][+]

impl AsRef<str> for str[src][+]

impl<'_, T> AsRef<[T]> for Iter<'_, T>1.13.0[src][+]

impl<'_, T> AsRef<[T]> for IterMut<'_, T>1.53.0[src][+]

impl<'_, T, U> AsRef<U> for &'_ T where
    T: AsRef<U> + ?Sized,
    U: ?Sized
[src][+]

impl<'_, T, U> AsRef<U> for &'_ mut T where
    T: AsRef<U> + ?Sized,
    U: ?Sized
[src][+]

impl<T> AsRef<[T]> for [T][src][+]

impl<T, const N: usize> AsRef<[T]> for [T; N][src][+]

impl<T: ?Sized + Pointable> AsRef<T> for Owned<T>

impl<L, R, Target> AsRef<Target> for Either<L, R> where
    L: AsRef<Target>,
    R: AsRef<Target>, 

impl<L, R> AsRef<str> for Either<L, R> where
    L: AsRef<str>,
    R: AsRef<str>, 

impl<L, R, Target> AsRef<[Target]> for Either<L, R> where
    L: AsRef<[Target]>,
    R: AsRef<[Target]>, 

impl AsRef<[u8]> for Mmap

impl AsRef<[u8]> for MmapMut

impl AsRef<str> for Signal

impl AsRef<sigset_t> for SigSet

impl AsRef<timespec> for TimeSpec

impl AsRef<timeval> for TimeVal

impl<A: Array> AsRef<[<A as Array>::Item]> for SmallVec<A>

impl AsRef<Proxy<WlDisplay>> for WlDisplay

impl AsRef<Proxy<WlRegistry>> for WlRegistry

impl AsRef<Proxy<WlCallback>> for WlCallback

impl AsRef<Proxy<WlCompositor>> for WlCompositor

impl AsRef<Proxy<WlShmPool>> for WlShmPool

impl AsRef<Proxy<WlShm>> for WlShm

impl AsRef<Proxy<WlBuffer>> for WlBuffer

impl AsRef<Proxy<WlDataOffer>> for WlDataOffer

impl AsRef<Proxy<WlDataSource>> for WlDataSource

impl AsRef<Proxy<WlDataDevice>> for WlDataDevice

impl AsRef<Proxy<WlDataDeviceManager>> for WlDataDeviceManager

impl AsRef<Proxy<WlShell>> for WlShell

impl AsRef<Proxy<WlShellSurface>> for WlShellSurface

impl AsRef<Proxy<WlSurface>> for WlSurface

impl AsRef<Proxy<WlSeat>> for WlSeat

impl AsRef<Proxy<WlPointer>> for WlPointer

impl AsRef<Proxy<WlKeyboard>> for WlKeyboard

impl AsRef<Proxy<WlTouch>> for WlTouch

impl AsRef<Proxy<WlOutput>> for WlOutput

impl AsRef<Proxy<WlRegion>> for WlRegion

impl AsRef<Proxy<WlSubcompositor>> for WlSubcompositor

impl AsRef<Proxy<WlSubsurface>> for WlSubsurface

impl AsRef<Proxy<AnonymousObject>> for AnonymousObject

impl AsRef<Proxy<ZwpFullscreenShellV1>> for ZwpFullscreenShellV1

impl AsRef<Proxy<ZwpFullscreenShellModeFeedbackV1>> for ZwpFullscreenShellModeFeedbackV1

impl AsRef<Proxy<ZwpIdleInhibitManagerV1>> for ZwpIdleInhibitManagerV1

impl AsRef<Proxy<ZwpIdleInhibitorV1>> for ZwpIdleInhibitorV1

impl AsRef<Proxy<ZwpInputMethodContextV1>> for ZwpInputMethodContextV1

impl AsRef<Proxy<ZwpInputMethodV1>> for ZwpInputMethodV1

impl AsRef<Proxy<ZwpInputPanelV1>> for ZwpInputPanelV1

impl AsRef<Proxy<ZwpInputPanelSurfaceV1>> for ZwpInputPanelSurfaceV1

impl AsRef<Proxy<ZwpInputTimestampsManagerV1>> for ZwpInputTimestampsManagerV1

impl AsRef<Proxy<ZwpInputTimestampsV1>> for ZwpInputTimestampsV1

impl AsRef<Proxy<ZwpKeyboardShortcutsInhibitManagerV1>> for ZwpKeyboardShortcutsInhibitManagerV1

impl AsRef<Proxy<ZwpKeyboardShortcutsInhibitorV1>> for ZwpKeyboardShortcutsInhibitorV1

impl AsRef<Proxy<ZwpLinuxDmabufV1>> for ZwpLinuxDmabufV1

impl AsRef<Proxy<ZwpLinuxBufferParamsV1>> for ZwpLinuxBufferParamsV1

impl AsRef<Proxy<ZwpLinuxExplicitSynchronizationV1>> for ZwpLinuxExplicitSynchronizationV1

impl AsRef<Proxy<ZwpLinuxSurfaceSynchronizationV1>> for ZwpLinuxSurfaceSynchronizationV1

impl AsRef<Proxy<ZwpLinuxBufferReleaseV1>> for ZwpLinuxBufferReleaseV1

impl AsRef<Proxy<ZwpPointerConstraintsV1>> for ZwpPointerConstraintsV1

impl AsRef<Proxy<ZwpLockedPointerV1>> for ZwpLockedPointerV1

impl AsRef<Proxy<ZwpConfinedPointerV1>> for ZwpConfinedPointerV1

impl AsRef<Proxy<ZwpPointerGesturesV1>> for ZwpPointerGesturesV1

impl AsRef<Proxy<ZwpPointerGestureSwipeV1>> for ZwpPointerGestureSwipeV1

impl AsRef<Proxy<ZwpPointerGesturePinchV1>> for ZwpPointerGesturePinchV1

impl AsRef<Proxy<ZwpPrimarySelectionDeviceManagerV1>> for ZwpPrimarySelectionDeviceManagerV1

impl AsRef<Proxy<ZwpPrimarySelectionDeviceV1>> for ZwpPrimarySelectionDeviceV1

impl AsRef<Proxy<ZwpPrimarySelectionOfferV1>> for ZwpPrimarySelectionOfferV1

impl AsRef<Proxy<ZwpPrimarySelectionSourceV1>> for ZwpPrimarySelectionSourceV1

impl AsRef<Proxy<ZwpRelativePointerManagerV1>> for ZwpRelativePointerManagerV1

impl AsRef<Proxy<ZwpRelativePointerV1>> for ZwpRelativePointerV1

impl AsRef<Proxy<ZwpTabletManagerV1>> for ZwpTabletManagerV1

impl AsRef<Proxy<ZwpTabletSeatV1>> for ZwpTabletSeatV1

impl AsRef<Proxy<ZwpTabletToolV1>> for ZwpTabletToolV1

impl AsRef<Proxy<ZwpTabletV1>> for ZwpTabletV1

impl AsRef<Proxy<ZwpTabletManagerV2>> for ZwpTabletManagerV2

impl AsRef<Proxy<ZwpTabletSeatV2>> for ZwpTabletSeatV2

impl AsRef<Proxy<ZwpTabletToolV2>> for ZwpTabletToolV2

impl AsRef<Proxy<ZwpTabletV2>> for ZwpTabletV2

impl AsRef<Proxy<ZwpTabletPadRingV2>> for ZwpTabletPadRingV2

impl AsRef<Proxy<ZwpTabletPadStripV2>> for ZwpTabletPadStripV2

impl AsRef<Proxy<ZwpTabletPadGroupV2>> for ZwpTabletPadGroupV2

impl AsRef<Proxy<ZwpTabletPadV2>> for ZwpTabletPadV2

impl AsRef<Proxy<ZwpTextInputV1>> for ZwpTextInputV1

impl AsRef<Proxy<ZwpTextInputManagerV1>> for ZwpTextInputManagerV1

impl AsRef<Proxy<ZwpTextInputV3>> for ZwpTextInputV3

impl AsRef<Proxy<ZwpTextInputManagerV3>> for ZwpTextInputManagerV3

impl AsRef<Proxy<ZxdgDecorationManagerV1>> for ZxdgDecorationManagerV1

impl AsRef<Proxy<ZxdgToplevelDecorationV1>> for ZxdgToplevelDecorationV1

impl AsRef<Proxy<ZxdgExporterV1>> for ZxdgExporterV1

impl AsRef<Proxy<ZxdgImporterV1>> for ZxdgImporterV1

impl AsRef<Proxy<ZxdgExportedV1>> for ZxdgExportedV1

impl AsRef<Proxy<ZxdgImportedV1>> for ZxdgImportedV1

impl AsRef<Proxy<ZxdgExporterV2>> for ZxdgExporterV2

impl AsRef<Proxy<ZxdgImporterV2>> for ZxdgImporterV2

impl AsRef<Proxy<ZxdgExportedV2>> for ZxdgExportedV2

impl AsRef<Proxy<ZxdgImportedV2>> for ZxdgImportedV2

impl AsRef<Proxy<ZxdgOutputManagerV1>> for ZxdgOutputManagerV1

impl AsRef<Proxy<ZxdgOutputV1>> for ZxdgOutputV1

impl AsRef<Proxy<XdgShell>> for XdgShell

impl AsRef<Proxy<XdgSurface>> for XdgSurface

impl AsRef<Proxy<XdgPopup>> for XdgPopup

impl AsRef<Proxy<ZxdgShellV6>> for ZxdgShellV6

impl AsRef<Proxy<ZxdgPositionerV6>> for ZxdgPositionerV6

impl AsRef<Proxy<ZxdgSurfaceV6>> for ZxdgSurfaceV6

impl AsRef<Proxy<ZxdgToplevelV6>> for ZxdgToplevelV6

impl AsRef<Proxy<ZxdgPopupV6>> for ZxdgPopupV6

impl AsRef<Proxy<ZwpXwaylandKeyboardGrabManagerV1>> for ZwpXwaylandKeyboardGrabManagerV1

impl AsRef<Proxy<ZwpXwaylandKeyboardGrabV1>> for ZwpXwaylandKeyboardGrabV1

impl AsRef<Proxy<GtkPrimarySelectionDeviceManager>> for GtkPrimarySelectionDeviceManager

impl AsRef<Proxy<GtkPrimarySelectionDevice>> for GtkPrimarySelectionDevice

impl AsRef<Proxy<GtkPrimarySelectionOffer>> for GtkPrimarySelectionOffer

impl AsRef<Proxy<GtkPrimarySelectionSource>> for GtkPrimarySelectionSource

impl AsRef<Proxy<ZwlrDataControlManagerV1>> for ZwlrDataControlManagerV1

impl AsRef<Proxy<ZwlrDataControlDeviceV1>> for ZwlrDataControlDeviceV1

impl AsRef<Proxy<ZwlrDataControlSourceV1>> for ZwlrDataControlSourceV1

impl AsRef<Proxy<ZwlrDataControlOfferV1>> for ZwlrDataControlOfferV1

impl AsRef<Proxy<ZwlrExportDmabufManagerV1>> for ZwlrExportDmabufManagerV1

impl AsRef<Proxy<ZwlrExportDmabufFrameV1>> for ZwlrExportDmabufFrameV1

impl AsRef<Proxy<ZwlrForeignToplevelManagerV1>> for ZwlrForeignToplevelManagerV1

impl AsRef<Proxy<ZwlrForeignToplevelHandleV1>> for ZwlrForeignToplevelHandleV1

impl AsRef<Proxy<ZwlrGammaControlManagerV1>> for ZwlrGammaControlManagerV1

impl AsRef<Proxy<ZwlrGammaControlV1>> for ZwlrGammaControlV1

impl AsRef<Proxy<ZwlrInputInhibitManagerV1>> for ZwlrInputInhibitManagerV1

impl AsRef<Proxy<ZwlrInputInhibitorV1>> for ZwlrInputInhibitorV1

impl AsRef<Proxy<ZwlrLayerShellV1>> for ZwlrLayerShellV1

impl AsRef<Proxy<ZwlrLayerSurfaceV1>> for ZwlrLayerSurfaceV1

impl AsRef<Proxy<ZwlrOutputManagerV1>> for ZwlrOutputManagerV1

impl AsRef<Proxy<ZwlrOutputHeadV1>> for ZwlrOutputHeadV1

impl AsRef<Proxy<ZwlrOutputModeV1>> for ZwlrOutputModeV1

impl AsRef<Proxy<ZwlrOutputConfigurationV1>> for ZwlrOutputConfigurationV1

impl AsRef<Proxy<ZwlrOutputConfigurationHeadV1>> for ZwlrOutputConfigurationHeadV1

impl AsRef<Proxy<ZwlrOutputPowerManagerV1>> for ZwlrOutputPowerManagerV1

impl AsRef<Proxy<ZwlrOutputPowerV1>> for ZwlrOutputPowerV1

impl AsRef<Proxy<ZwlrScreencopyManagerV1>> for ZwlrScreencopyManagerV1

impl AsRef<Proxy<ZwlrScreencopyFrameV1>> for ZwlrScreencopyFrameV1

impl AsRef<Proxy<ZwlrVirtualPointerV1>> for ZwlrVirtualPointerV1

impl AsRef<Proxy<ZwlrVirtualPointerManagerV1>> for ZwlrVirtualPointerManagerV1

impl AsRef<Proxy<WpPresentation>> for WpPresentation

impl AsRef<Proxy<WpPresentationFeedback>> for WpPresentationFeedback

impl AsRef<Proxy<XdgWmBase>> for XdgWmBase

impl AsRef<Proxy<XdgPositioner>> for XdgPositioner

impl AsRef<Proxy<XdgSurface>> for XdgSurface

impl AsRef<Proxy<XdgToplevel>> for XdgToplevel

impl AsRef<Proxy<XdgPopup>> for XdgPopup

impl AsRef<Proxy<WpViewporter>> for WpViewporter

impl AsRef<Proxy<WpViewport>> for WpViewport

impl AsRef<XAnyEvent> for XEvent

impl AsRef<XButtonEvent> for XEvent

impl AsRef<XCirculateEvent> for XEvent

impl AsRef<XCirculateRequestEvent> for XEvent

impl AsRef<XClientMessageEvent> for XEvent

impl AsRef<XColormapEvent> for XEvent

impl AsRef<XConfigureEvent> for XEvent

impl AsRef<XConfigureRequestEvent> for XEvent

impl AsRef<XCreateWindowEvent> for XEvent

impl AsRef<XCrossingEvent> for XEvent

impl AsRef<XDestroyWindowEvent> for XEvent

impl AsRef<XErrorEvent> for XEvent

impl AsRef<XExposeEvent> for XEvent

impl AsRef<XFocusChangeEvent> for XEvent

impl AsRef<XGenericEventCookie> for XEvent

impl AsRef<XGraphicsExposeEvent> for XEvent

impl AsRef<XGravityEvent> for XEvent

impl AsRef<XKeyEvent> for XEvent

impl AsRef<XKeymapEvent> for XEvent

impl AsRef<XMapEvent> for XEvent

impl AsRef<XMappingEvent> for XEvent

impl AsRef<XMapRequestEvent> for XEvent

impl AsRef<XMotionEvent> for XEvent

impl AsRef<XNoExposeEvent> for XEvent

impl AsRef<XPropertyEvent> for XEvent

impl AsRef<XReparentEvent> for XEvent

impl AsRef<XResizeRequestEvent> for XEvent

impl AsRef<XSelectionClearEvent> for XEvent

impl AsRef<XSelectionEvent> for XEvent

impl AsRef<XSelectionRequestEvent> for XEvent

impl AsRef<XUnmapEvent> for XEvent

impl AsRef<XVisibilityEvent> for XEvent

impl AsRef<[i8]> for ClientMessageData

impl AsRef<[u8]> for ClientMessageData

impl AsRef<[i16]> for ClientMessageData

impl AsRef<[u16]> for ClientMessageData

impl AsRef<[i64]> for ClientMessageData

impl AsRef<[u64]> for ClientMessageData

impl AsRef<XF86VidModeNotifyEvent> for XEvent

impl AsRef<XScreenSaverNotifyEvent> for XEvent

impl AsRef<XRRScreenChangeNotifyEvent> for XEvent

impl AsRef<XRRNotifyEvent> for XEvent

impl AsRef<XRROutputChangeNotifyEvent> for XEvent

impl AsRef<XRRCrtcChangeNotifyEvent> for XEvent

impl AsRef<XRROutputPropertyNotifyEvent> for XEvent

impl AsRef<XRRProviderChangeNotifyEvent> for XEvent

impl AsRef<XRRProviderPropertyNotifyEvent> for XEvent

impl AsRef<XRRResourceChangeNotifyEvent> for XEvent