Trait otter_api_tests::imports::failure::_core::convert::AsRef 1.0.0[−][src]
Expand description
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:
- Unlike
AsRef
,Borrow
has a blanket impl for anyT
, and can be used to accept either a reference or a value. Borrow
also requires thatHash
,Eq
andOrd
for borrowed value are equivalent to those of the owned value. For this reason, if you want to borrow only a single field of a struct you can implementAsRef
, but notBorrow
.
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
AsRef
auto-dereferences if the inner type is a reference or a mutable reference (e.g.:foo.as_ref()
will work the same iffoo
has type&mut Foo
or&&mut Foo
)
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
Implementations on Foreign Types
impl AsRef<SystemTime> for Timestamp
[src]
impl AsRef<SystemTime> for Timestamp
[src]pub fn as_ref(&self) -> &SystemTime
[src]
impl AsRef<X509NameEntryRef> for X509NameEntry
[src]
impl AsRef<X509NameEntryRef> for X509NameEntry
[src]pub fn as_ref(&self) -> &X509NameEntryRef
[src]
impl AsRef<X509StoreRef> for X509Store
[src]
impl AsRef<X509StoreRef> for X509Store
[src]pub fn as_ref(&self) -> &X509StoreRef
[src]
impl AsRef<X509ObjectRef> for X509Object
[src]
impl AsRef<X509ObjectRef> for X509Object
[src]pub fn as_ref(&self) -> &X509ObjectRef
[src]
impl AsRef<OcspCertIdRef> for OcspCertId
[src]
impl AsRef<OcspCertIdRef> for OcspCertId
[src]pub fn as_ref(&self) -> &OcspCertIdRef
[src]
impl AsRef<GeneralNameRef> for GeneralName
[src]
impl AsRef<GeneralNameRef> for GeneralName
[src]pub fn as_ref(&self) -> &GeneralNameRef
[src]
impl AsRef<Asn1StringRef> for Asn1String
[src]
impl AsRef<Asn1StringRef> for Asn1String
[src]pub fn as_ref(&self) -> &Asn1StringRef
[src]
impl AsRef<OcspOneReqRef> for OcspOneReq
[src]
impl AsRef<OcspOneReqRef> for OcspOneReq
[src]pub fn as_ref(&self) -> &OcspOneReqRef
[src]
impl AsRef<Asn1BitStringRef> for Asn1BitString
[src]
impl AsRef<Asn1BitStringRef> for Asn1BitString
[src]pub fn as_ref(&self) -> &Asn1BitStringRef
[src]
impl AsRef<X509ExtensionRef> for X509Extension
[src]
impl AsRef<X509ExtensionRef> for X509Extension
[src]pub fn as_ref(&self) -> &X509ExtensionRef
[src]
impl AsRef<OcspResponseRef> for OcspResponse
[src]
impl AsRef<OcspResponseRef> for OcspResponse
[src]pub fn as_ref(&self) -> &OcspResponseRef
[src]
impl AsRef<BigNumContextRef> for BigNumContext
[src]
impl AsRef<BigNumContextRef> for BigNumContext
[src]pub fn as_ref(&self) -> &BigNumContextRef
[src]
impl AsRef<SslContextRef> for SslContext
[src]
impl AsRef<SslContextRef> for SslContext
[src]pub fn as_ref(&self) -> &SslContextRef
[src]
impl AsRef<Asn1IntegerRef> for Asn1Integer
[src]
impl AsRef<Asn1IntegerRef> for Asn1Integer
[src]pub fn as_ref(&self) -> &Asn1IntegerRef
[src]
impl AsRef<OcspBasicResponseRef> for OcspBasicResponse
[src]
impl AsRef<OcspBasicResponseRef> for OcspBasicResponse
[src]pub fn as_ref(&self) -> &OcspBasicResponseRef
[src]
impl AsRef<AccessDescriptionRef> for AccessDescription
[src]
impl AsRef<AccessDescriptionRef> for AccessDescription
[src]pub fn as_ref(&self) -> &AccessDescriptionRef
[src]
impl AsRef<Asn1ObjectRef> for Asn1Object
[src]
impl AsRef<Asn1ObjectRef> for Asn1Object
[src]pub fn as_ref(&self) -> &Asn1ObjectRef
[src]
impl AsRef<X509AlgorithmRef> for X509Algorithm
[src]
impl AsRef<X509AlgorithmRef> for X509Algorithm
[src]pub fn as_ref(&self) -> &X509AlgorithmRef
[src]
impl AsRef<Asn1GeneralizedTimeRef> for Asn1GeneralizedTime
[src]
impl AsRef<Asn1GeneralizedTimeRef> for Asn1GeneralizedTime
[src]pub fn as_ref(&self) -> &Asn1GeneralizedTimeRef
[src]
impl AsRef<X509VerifyParamRef> for X509VerifyParam
[src]
impl AsRef<X509VerifyParamRef> for X509VerifyParam
[src]pub fn as_ref(&self) -> &X509VerifyParamRef
[src]
impl AsRef<CmsContentInfoRef> for CmsContentInfo
[src]
impl AsRef<CmsContentInfoRef> for CmsContentInfo
[src]pub fn as_ref(&self) -> &CmsContentInfoRef
[src]
impl<T> AsRef<X509LookupMethodRef<T>> for X509LookupMethod<T>
[src]
impl<T> AsRef<X509LookupMethodRef<T>> for X509LookupMethod<T>
[src]pub fn as_ref(&self) -> &X509LookupMethodRef<T>
[src]
impl AsRef<EcdsaSigRef> for EcdsaSig
[src]
impl AsRef<EcdsaSigRef> for EcdsaSig
[src]pub fn as_ref(&self) -> &EcdsaSigRef
[src]
impl<T> AsRef<X509LookupRef<T>> for X509Lookup<T>
[src]
impl<T> AsRef<X509LookupRef<T>> for X509Lookup<T>
[src]pub fn as_ref(&self) -> &X509LookupRef<T>
[src]
impl AsRef<SrtpProtectionProfileRef> for SrtpProtectionProfile
[src]
impl AsRef<SrtpProtectionProfileRef> for SrtpProtectionProfile
[src]pub fn as_ref(&self) -> &SrtpProtectionProfileRef
[src]
impl AsRef<X509ReqRef> for X509Req
[src]
impl AsRef<X509ReqRef> for X509Req
[src]pub fn as_ref(&self) -> &X509ReqRef
[src]
impl AsRef<X509StoreContextRef> for X509StoreContext
[src]
impl AsRef<X509StoreContextRef> for X509StoreContext
[src]pub fn as_ref(&self) -> &X509StoreContextRef
[src]
impl AsRef<EcPointRef> for EcPoint
[src]
impl AsRef<EcPointRef> for EcPoint
[src]pub fn as_ref(&self) -> &EcPointRef
[src]
impl AsRef<OpensslStringRef> for OpensslString
[src]
impl AsRef<OpensslStringRef> for OpensslString
[src]pub fn as_ref(&self) -> &OpensslStringRef
[src]
impl AsRef<Asn1TimeRef> for Asn1Time
[src]
impl AsRef<Asn1TimeRef> for Asn1Time
[src]pub fn as_ref(&self) -> &Asn1TimeRef
[src]
impl AsRef<X509NameRef> for X509Name
[src]
impl AsRef<X509NameRef> for X509Name
[src]pub fn as_ref(&self) -> &X509NameRef
[src]
impl AsRef<SslSessionRef> for SslSession
[src]
impl AsRef<SslSessionRef> for SslSession
[src]pub fn as_ref(&self) -> &SslSessionRef
[src]
impl AsRef<EcGroupRef> for EcGroup
[src]
impl AsRef<EcGroupRef> for EcGroup
[src]pub fn as_ref(&self) -> &EcGroupRef
[src]
impl AsRef<X509StoreBuilderRef> for X509StoreBuilder
[src]
impl AsRef<X509StoreBuilderRef> for X509StoreBuilder
[src]pub fn as_ref(&self) -> &X509StoreBuilderRef
[src]
impl AsRef<OcspRequestRef> for OcspRequest
[src]
impl AsRef<OcspRequestRef> for OcspRequest
[src]pub fn as_ref(&self) -> &OcspRequestRef
[src]
Implementors
impl<I, A> AsRef<IndexSlice<I, [A]>> for IndexVec<I, A> where
I: Idx,
impl<I, A> AsRef<IndexSlice<I, [A]>> for IndexVec<I, A> where
I: Idx,
pub fn as_ref(&self) -> &IndexSlice<I, [A]>
impl<L, R> AsRef<OsStr> for Either<L, R> where
L: AsRef<OsStr>,
R: AsRef<OsStr>,
[src]
impl<L, R> AsRef<OsStr> for Either<L, R> where
L: AsRef<OsStr>,
R: AsRef<OsStr>,
[src]Requires crate feature use_std
.
impl<L, R> AsRef<CStr> for Either<L, R> where
L: AsRef<CStr>,
R: AsRef<CStr>,
[src]
impl<L, R> AsRef<CStr> for Either<L, R> where
L: AsRef<CStr>,
R: AsRef<CStr>,
[src]Requires crate feature use_std
.
impl<L, R> AsRef<Path> for Either<L, R> where
L: AsRef<Path>,
R: AsRef<Path>,
[src]
impl<L, R> AsRef<Path> for Either<L, R> where
L: AsRef<Path>,
R: AsRef<Path>,
[src]Requires crate feature use_std
.
impl<L, R, Target> AsRef<[Target]> for Either<L, R> where
L: AsRef<[Target]>,
R: AsRef<[Target]>,
[src]
impl<L, R, Target> AsRef<[Target]> for Either<L, R> where
L: AsRef<[Target]>,
R: AsRef<[Target]>,
[src]impl<T> AsRef<[T; 32]> for GenericArray<T, UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>>
impl<T> AsRef<[T; 32]> for GenericArray<T, UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>>
impl<T> AsRef<T> for OrderedFloat<T> where
T: Float,
impl<T> AsRef<T> for OrderedFloat<T> where
T: Float,
impl<T, N> AsRef<[T]> for GenericArray<T, N> where
N: ArrayLength<T>,
impl<T, N> AsRef<[T]> for GenericArray<T, N> where
N: ArrayLength<T>,