Trait nom::lib::std::convert::AsRef1.0.0[][src]

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

Notable traits for &'_ mut I

impl<'_, I> Iterator for &'_ mut I where
    I: Iterator + ?Sized
type Item = <I as Iterator>::Item;
; }
[]

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

Notable traits for &'_ mut I

impl<'_, I> Iterator for &'_ mut I where
    I: Iterator + ?Sized
type Item = <I as Iterator>::Item;
[src][]

Performs the conversion.

Implementations on Foreign Types

impl<'_> AsRef<Path> for Components<'_>[src][]

impl AsRef<Path> for OsStr[src][]

impl AsRef<Path> for PathBuf[src][]

impl<'_> AsRef<OsStr> for Iter<'_>[src][]

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

impl AsRef<OsStr> for OsString[src][]

impl<'_> AsRef<OsStr> for Component<'_>[src][]

impl<'_> AsRef<Path> for Component<'_>[src][]

impl AsRef<OsStr> for Path[src][]

impl<'_> AsRef<Path> for Iter<'_>[src][]

impl AsRef<OsStr> for PathBuf[src][]

impl AsRef<Path> for Path[src][]

impl AsRef<OsStr> for OsStr[src][]

impl AsRef<CStr> for CStr[src][]

impl AsRef<CStr> for CString[src][]

impl<'_> AsRef<OsStr> for Components<'_>[src][]

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

impl AsRef<Path> for OsString[src][]

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

impl<T> AsRef<[T]> for [T][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 AsRef<[u8]> for str[src][]

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

impl<T> AsRef<T> for Arc<T> where
    T: ?Sized
[src][]

impl<T> AsRef<T> for Rc<T> where
    T: ?Sized
[src][]

Implementors

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

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

impl AsRef<OsStr> for String[src][+]

impl AsRef<Path> for String[src][+]

impl<'_> AsRef<Path> for Cow<'_, OsStr>1.8.0[src][+]

impl<'_, T> AsRef<[T]> for nom::lib::std::slice::Iter<'_, T>1.13.0[src][+]

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

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

impl<'a, T, A> AsRef<[T]> for Drain<'a, T, A> where
    A: Allocator
1.46.0[src][+]

impl<T, A> AsRef<[T]> for IntoIter<T, A> where
    A: Allocator
1.46.0[src][+]

impl<T, A> AsRef<[T]> for Vec<T, A> where
    A: Allocator
[src][+]

impl<T, A> AsRef<Vec<T, A>> for Vec<T, A> where
    A: Allocator
[src][+]

impl<T, A> AsRef<T> for Box<T, A> where
    T: ?Sized,
    A: Allocator
1.5.0[src][+]

impl AsRef<dyn Error + 'static + Sync + Send> for Error

impl AsRef<dyn Error + 'static> for Error

impl<A: Array<Item = u8>> AsRef<str> for ArrayString<A>

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

impl AsRef<[u8]> for BString

impl AsRef<BStr> for BString

impl AsRef<[u8]> for BStr

impl AsRef<BStr> for [u8]

impl AsRef<[u8]> for Bytes

impl AsRef<[u8]> for BytesMut

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

impl AsRef<Ident> for IdentString

impl AsRef<str> for IdentString

impl<T> AsRef<T> for SpannedValue<T>

impl AsRef<str> for CodeId

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<dyn Fail + 'static> for Error

impl<T: AsRef<[u8]>> AsRef<[u8]> for Window<T>

impl<T, N> AsRef<[T]> for GenericArray<T, N> where
    N: ArrayLength<T>, 

impl<T> AsRef<[T; 1]> for GenericArray<T, U1>

impl<T> AsRef<[T; 2]> for GenericArray<T, U2>

impl<T> AsRef<[T; 3]> for GenericArray<T, U3>

impl<T> AsRef<[T; 4]> for GenericArray<T, U4>

impl<T> AsRef<[T; 5]> for GenericArray<T, U5>

impl<T> AsRef<[T; 6]> for GenericArray<T, U6>

impl<T> AsRef<[T; 7]> for GenericArray<T, U7>

impl<T> AsRef<[T; 8]> for GenericArray<T, U8>

impl<T> AsRef<[T; 9]> for GenericArray<T, U9>

impl<T> AsRef<[T; 10]> for GenericArray<T, U10>

impl<T> AsRef<[T; 11]> for GenericArray<T, U11>

impl<T> AsRef<[T; 12]> for GenericArray<T, U12>

impl<T> AsRef<[T; 13]> for GenericArray<T, U13>

impl<T> AsRef<[T; 14]> for GenericArray<T, U14>

impl<T> AsRef<[T; 15]> for GenericArray<T, U15>

impl<T> AsRef<[T; 16]> for GenericArray<T, U16>

impl<T> AsRef<[T; 17]> for GenericArray<T, U17>

impl<T> AsRef<[T; 18]> for GenericArray<T, U18>

impl<T> AsRef<[T; 19]> for GenericArray<T, U19>

impl<T> AsRef<[T; 20]> for GenericArray<T, U20>

impl<T> AsRef<[T; 21]> for GenericArray<T, U21>

impl<T> AsRef<[T; 22]> for GenericArray<T, U22>

impl<T> AsRef<[T; 23]> for GenericArray<T, U23>

impl<T> AsRef<[T; 24]> for GenericArray<T, U24>

impl<T> AsRef<[T; 25]> for GenericArray<T, U25>

impl<T> AsRef<[T; 26]> for GenericArray<T, U26>

impl<T> AsRef<[T; 27]> for GenericArray<T, U27>

impl<T> AsRef<[T; 28]> for GenericArray<T, U28>

impl<T> AsRef<[T; 29]> for GenericArray<T, U29>

impl<T> AsRef<[T; 30]> for GenericArray<T, U30>

impl<T> AsRef<[T; 31]> for GenericArray<T, U31>

impl<T> AsRef<[T; 32]> for GenericArray<T, U32>

impl AsRef<str> for HeaderName

impl AsRef<[u8]> for HeaderName

impl AsRef<[u8]> for HeaderValue

impl AsRef<str> for Method

impl AsRef<str> for Authority

impl<T> AsRef<str> for Port<T> where
    T: AsRef<str>, 

impl AsRef<str> for Scheme

impl AsRef<[u8]> for Mmap

impl AsRef<[u8]> for MmapMut

impl AsRef<str> for Mime

impl<'a> AsRef<str> for Name<'a>

impl AsRef<str> for Signal

impl AsRef<sigset_t> for SigSet

impl AsRef<timespec> for TimeSpec

impl AsRef<timeval> for TimeVal

impl AsRef<str> for Buffer

impl<'a> AsRef<str> for DecimalStr<'a>

impl<'a> AsRef<str> for InfinityStr<'a>

impl<'a> AsRef<str> for MinusSignStr<'a>

impl<'a> AsRef<str> for NanStr<'a>

impl<'a> AsRef<str> for PlusSignStr<'a>

impl<'a> AsRef<str> for SeparatorStr<'a>

impl AsRef<Asn1GeneralizedTimeRef> for Asn1GeneralizedTime

impl AsRef<Asn1TimeRef> for Asn1Time

impl AsRef<Asn1StringRef> for Asn1String

impl AsRef<Asn1IntegerRef> for Asn1Integer

impl AsRef<Asn1BitStringRef> for Asn1BitString

impl AsRef<Asn1ObjectRef> for Asn1Object

impl AsRef<BigNumContextRef> for BigNumContext

impl AsRef<BigNumRef> for BigNum

impl AsRef<CmsContentInfoRef> for CmsContentInfo

impl AsRef<ConfRef> for Conf

impl<T> AsRef<DhRef<T>> for Dh<T>

impl<T> AsRef<DsaRef<T>> for Dsa<T>

impl AsRef<EcGroupRef> for EcGroup

impl AsRef<EcPointRef> for EcPoint

impl<T> AsRef<EcKeyRef<T>> for EcKey<T>

impl AsRef<EcdsaSigRef> for EcdsaSig

impl AsRef<[u8]> for DigestBytes

impl AsRef<OcspBasicResponseRef> for OcspBasicResponse

impl AsRef<OcspCertIdRef> for OcspCertId

impl AsRef<OcspResponseRef> for OcspResponse

impl AsRef<OcspRequestRef> for OcspRequest

impl AsRef<OcspOneReqRef> for OcspOneReq

impl AsRef<Pkcs12Ref> for Pkcs12

impl AsRef<Pkcs7Ref> for Pkcs7

impl<T> AsRef<PKeyRef<T>> for PKey<T>

impl<T> AsRef<RsaRef<T>> for Rsa<T>

impl AsRef<SrtpProtectionProfileRef> for SrtpProtectionProfile

impl AsRef<SslContextRef> for SslContext

impl AsRef<SslSessionRef> for SslSession

impl AsRef<SslRef> for Ssl

impl<T: Stackable> AsRef<StackRef<T>> for Stack<T>

impl AsRef<OpensslStringRef> for OpensslString

impl AsRef<str> for OpensslString

impl AsRef<[u8]> for OpensslString

impl AsRef<str> for OpensslStringRef

impl AsRef<[u8]> for OpensslStringRef

impl AsRef<X509VerifyParamRef> for X509VerifyParam

impl AsRef<X509StoreBuilderRef> for X509StoreBuilder

impl AsRef<X509StoreRef> for X509Store

impl AsRef<X509StoreContextRef> for X509StoreContext

impl AsRef<X509Ref> for X509

impl AsRef<X509Ref> for X509Ref

impl AsRef<X509ExtensionRef> for X509Extension

impl AsRef<X509NameRef> for X509Name

impl AsRef<X509NameEntryRef> for X509NameEntry

impl AsRef<X509ReqRef> for X509Req

impl AsRef<GeneralNameRef> for GeneralName

impl AsRef<X509AlgorithmRef> for X509Algorithm

impl<T: Float> AsRef<T> for OrderedFloat<T>

impl<T: Float> AsRef<T> for NotNan<T>

impl<T> AsRef<[T]> for RepeatedField<T>

impl<'a> AsRef<Event<'a>> for Event<'a>

impl AsRef<[u8]> for Literal

impl<T> AsRef<T> for Gray<T>

impl<T> AsRef<[T]> for RGB<T>

impl<T> AsRef<[T]> for RGBA<T>

impl<T> AsRef<T> for GrayAlpha<T>

impl<A> AsRef<[u8]> for Aad<A> where
    A: AsRef<[u8]>, 

impl AsRef<[u8]> for Tag

impl AsRef<[u8; 12]> for Nonce

impl AsRef<[u8]> for PublicKey

impl AsRef<[u8]> for Digest

impl AsRef<[u8]> for Tag

impl AsRef<[u8]> for Document

impl AsRef<[u8]> for RsaSubjectPublicKey

impl AsRef<[u8]> for Signature

impl AsRef<str> for Secret

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

impl AsRef<[u8]> for ByteView<'_>

impl AsRef<str> for Name<'_>

impl<'a> AsRef<str> for BucketName<'a>

impl<'a> AsRef<[u8]> for BucketName<'a>

impl<'a> AsRef<str> for ObjectName<'a>

impl<'a> AsRef<[u8]> for ObjectName<'a>

impl<'a> AsRef<BucketName<'a>> for ObjectId<'a>

impl<'a> AsRef<ObjectName<'a>> for ObjectId<'a>

impl AsRef<str> for Scopes

impl AsRef<Path> for TempDir

impl AsRef<Path> for TempPath

impl AsRef<OsStr> for TempPath

impl AsRef<Path> for NamedTempFile

impl AsRef<[RpnExpressionNode]> for RpnExpression

impl AsRef<[RpnExpressionNode]> for RpnExpressionBuilder

impl<T: MibArg> AsRef<[usize]> for Mib<T>

impl AsRef<TcpStream> for ReadHalf<'_>

impl AsRef<TcpStream> for WriteHalf<'_>

impl AsRef<TcpStream> for OwnedReadHalf

impl AsRef<TcpStream> for OwnedWriteHalf

impl AsRef<UdpSocket> for SendHalf

impl AsRef<UdpSocket> for RecvHalf

impl AsRef<UnixDatagram> for RecvHalf<'_>

impl AsRef<UnixDatagram> for SendHalf<'_>

impl AsRef<UnixDatagram> for OwnedSendHalf

impl AsRef<UnixDatagram> for OwnedRecvHalf

impl AsRef<UnixStream> for ReadHalf<'_>

impl AsRef<UnixStream> for WriteHalf<'_>

impl AsRef<UnixStream> for OwnedReadHalf

impl AsRef<UnixStream> for OwnedWriteHalf

impl AsRef<str> for Field

impl<S: AsRef<str>> AsRef<str> for Ascii<S>

impl<S: AsRef<str>> AsRef<str> for UniCase<S>

impl AsRef<str> for Url