pub type Fragment<'a> = Cow<'a, str>;
Expand description
A fragment of Text
.
This is just an alias to a string that may be either borrowed or owned.
Aliased Type§
enum Fragment<'a> {
Borrowed(&'a str),
Owned(String),
}
Variants§
Implementations
Source§impl<B> Cow<'_, B>
impl<B> Cow<'_, B>
Sourcepub const fn is_borrowed(&self) -> bool
🔬This is a nightly-only experimental API. (cow_is_borrowed
)
pub const fn is_borrowed(&self) -> bool
cow_is_borrowed
)Returns true if the data is borrowed, i.e. if to_mut
would require additional work.
§Examples
#![feature(cow_is_borrowed)]
use std::borrow::Cow;
let cow = Cow::Borrowed("moo");
assert!(cow.is_borrowed());
let bull: Cow<'_, str> = Cow::Owned("...moo?".to_string());
assert!(!bull.is_borrowed());
Sourcepub const fn is_owned(&self) -> bool
🔬This is a nightly-only experimental API. (cow_is_borrowed
)
pub const fn is_owned(&self) -> bool
cow_is_borrowed
)Returns true if the data is owned, i.e. if to_mut
would be a no-op.
§Examples
#![feature(cow_is_borrowed)]
use std::borrow::Cow;
let cow: Cow<'_, str> = Cow::Owned("moo".to_string());
assert!(cow.is_owned());
let bull = Cow::Borrowed("...moo?");
assert!(!bull.is_owned());
1.0.0 · Sourcepub fn to_mut(&mut self) -> &mut <B as ToOwned>::Owned
pub fn to_mut(&mut self) -> &mut <B as ToOwned>::Owned
Acquires a mutable reference to the owned form of the data.
Clones the data if it is not already owned.
§Examples
use std::borrow::Cow;
let mut cow = Cow::Borrowed("foo");
cow.to_mut().make_ascii_uppercase();
assert_eq!(
cow,
Cow::Owned(String::from("FOO")) as Cow<'_, str>
);
1.0.0 · Sourcepub fn into_owned(self) -> <B as ToOwned>::Owned
pub fn into_owned(self) -> <B as ToOwned>::Owned
Extracts the owned data.
Clones the data if it is not already owned.
§Examples
Calling into_owned
on a Cow::Borrowed
returns a clone of the borrowed data:
use std::borrow::Cow;
let s = "Hello world!";
let cow = Cow::Borrowed(s);
assert_eq!(
cow.into_owned(),
String::from(s)
);
Calling into_owned
on a Cow::Owned
returns the owned data. The data is moved out of the
Cow
without being cloned.
use std::borrow::Cow;
let s = "Hello world!";
let cow: Cow<'_, str> = Cow::Owned(String::from(s));
assert_eq!(
cow.into_owned(),
String::from(s)
);
Trait Implementations
1.14.0 · Source§impl<'a> AddAssign<&'a str> for Cow<'a, str>
Available on non-no_global_oom_handling
only.
impl<'a> AddAssign<&'a str> for Cow<'a, str>
no_global_oom_handling
only.Source§fn add_assign(&mut self, rhs: &'a str)
fn add_assign(&mut self, rhs: &'a str)
+=
operation. Read more§impl<'a> Arg for Cow<'a, str>
impl<'a> Arg for Cow<'a, str>
§fn to_string_lossy(&self) -> Cow<'_, str>
fn to_string_lossy(&self) -> Cow<'_, str>
Cow<'_, str>
.§fn as_cow_c_str(&self) -> Result<Cow<'_, CStr>, Errno>
fn as_cow_c_str(&self) -> Result<Cow<'_, CStr>, Errno>
CStr
.§impl<'a> Arg for Cow<'a, str>
Available on crate feature alloc
only.
impl<'a> Arg for Cow<'a, str>
alloc
only.§fn to_string_lossy(&self) -> Cow<'_, str>
fn to_string_lossy(&self) -> Cow<'_, str>
Cow<'_, str>
.§fn as_cow_c_str(&self) -> Result<Cow<'_, CStr>, Errno>
fn as_cow_c_str(&self) -> Result<Cow<'_, CStr>, Errno>
CStr
.§impl<T> AsRawXcbConnection for Cow<'_, T>
Available on crate feature alloc
only.
impl<T> AsRawXcbConnection for Cow<'_, T>
alloc
only.§fn as_raw_xcb_connection(&self) -> *mut xcb_connection_t
fn as_raw_xcb_connection(&self) -> *mut xcb_connection_t
§impl<C> Connection for Cow<'_, C>
impl<C> Connection for Cow<'_, C>
§fn wait_for_event(&self) -> Result<Event, ConnectionError>
fn wait_for_event(&self) -> Result<Event, ConnectionError>
§fn wait_for_raw_event(
&self,
) -> Result<<Cow<'_, C> as RequestConnection>::Buf, ConnectionError>
fn wait_for_raw_event( &self, ) -> Result<<Cow<'_, C> as RequestConnection>::Buf, ConnectionError>
§fn wait_for_event_with_sequence(&self) -> Result<(Event, u64), ConnectionError>
fn wait_for_event_with_sequence(&self) -> Result<(Event, u64), ConnectionError>
§fn wait_for_raw_event_with_sequence(
&self,
) -> Result<(<Cow<'_, C> as RequestConnection>::Buf, u64), ConnectionError>
fn wait_for_raw_event_with_sequence( &self, ) -> Result<(<Cow<'_, C> as RequestConnection>::Buf, u64), ConnectionError>
§fn poll_for_event(&self) -> Result<Option<Event>, ConnectionError>
fn poll_for_event(&self) -> Result<Option<Event>, ConnectionError>
§fn poll_for_raw_event(
&self,
) -> Result<Option<<Cow<'_, C> as RequestConnection>::Buf>, ConnectionError>
fn poll_for_raw_event( &self, ) -> Result<Option<<Cow<'_, C> as RequestConnection>::Buf>, ConnectionError>
§fn poll_for_event_with_sequence(
&self,
) -> Result<Option<(Event, u64)>, ConnectionError>
fn poll_for_event_with_sequence( &self, ) -> Result<Option<(Event, u64)>, ConnectionError>
§fn poll_for_raw_event_with_sequence(
&self,
) -> Result<Option<(<Cow<'_, C> as RequestConnection>::Buf, u64)>, ConnectionError>
fn poll_for_raw_event_with_sequence( &self, ) -> Result<Option<(<Cow<'_, C> as RequestConnection>::Buf, u64)>, ConnectionError>
§fn generate_id(&self) -> Result<u32, ReplyOrIdError>
fn generate_id(&self) -> Result<u32, ReplyOrIdError>
Source§impl<'de, 'a, T> Deserialize<'de> for Cow<'a, T>
Available on crate features std
or alloc
only.
impl<'de, 'a, T> Deserialize<'de> for Cow<'a, T>
std
or alloc
only.Source§fn deserialize<D>(
deserializer: D,
) -> Result<Cow<'a, T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Cow<'a, T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
§impl<T> EncodeAsVarULE<T> for Cow<'_, T>
impl<T> EncodeAsVarULE<T> for Cow<'_, T>
§fn encode_var_ule_as_slices<R>(&self, cb: impl FnOnce(&[&[u8]]) -> R) -> R
fn encode_var_ule_as_slices<R>(&self, cb: impl FnOnce(&[&[u8]]) -> R) -> R
cb
with a piecewise list of byte slices that when concatenated
produce the memory pattern of the corresponding instance of T
. Read more§fn encode_var_ule_len(&self) -> usize
fn encode_var_ule_len(&self) -> usize
VarULE
] type§fn encode_var_ule_write(&self, dst: &mut [u8])
fn encode_var_ule_write(&self, dst: &mut [u8])
VarULE
] type to the dst
buffer. dst
should
be the size of [Self::encode_var_ule_len()
]1.28.0 · Source§impl<'a> From<&'a String> for Cow<'a, str>
Available on non-no_global_oom_handling
only.
impl<'a> From<&'a String> for Cow<'a, str>
no_global_oom_handling
only.1.12.0 · Source§impl<'a, 'b> FromIterator<&'b str> for Cow<'a, str>
Available on non-no_global_oom_handling
only.
impl<'a, 'b> FromIterator<&'b str> for Cow<'a, str>
no_global_oom_handling
only.1.12.0 · Source§impl<'a> FromIterator<String> for Cow<'a, str>
Available on non-no_global_oom_handling
only.
impl<'a> FromIterator<String> for Cow<'a, str>
no_global_oom_handling
only.1.12.0 · Source§impl<'a> FromIterator<char> for Cow<'a, str>
Available on non-no_global_oom_handling
only.
impl<'a> FromIterator<char> for Cow<'a, str>
no_global_oom_handling
only.§impl<'a, C, T> FromParallelIterator<T> for Cow<'a, C>
Collects an arbitrary Cow
collection.
impl<'a, C, T> FromParallelIterator<T> for Cow<'a, C>
Collects an arbitrary Cow
collection.
Note, the standard library only has FromIterator
for Cow<'a, str>
and
Cow<'a, [T]>
, because no one thought to add a blanket implementation
before it was stabilized.
§fn from_par_iter<I>(par_iter: I) -> Cow<'a, C>where
I: IntoParallelIterator<Item = T>,
fn from_par_iter<I>(par_iter: I) -> Cow<'a, C>where
I: IntoParallelIterator<Item = T>,
par_iter
. Read moreSource§impl<T> IdentFragment for Cow<'_, T>
impl<T> IdentFragment for Cow<'_, T>
Source§impl<'de, 'a, E> IntoDeserializer<'de, E> for Cow<'a, str>where
E: Error,
Available on crate features std
or alloc
only.
impl<'de, 'a, E> IntoDeserializer<'de, E> for Cow<'a, str>where
E: Error,
std
or alloc
only.Source§type Deserializer = CowStrDeserializer<'a, E>
type Deserializer = CowStrDeserializer<'a, E>
Source§fn into_deserializer(self) -> CowStrDeserializer<'a, E>
fn into_deserializer(self) -> CowStrDeserializer<'a, E>
Source§impl<'a> IntoFragment<'a> for Cow<'a, str>
impl<'a> IntoFragment<'a> for Cow<'a, str>
1.0.0 · Source§impl<B> Ord for Cow<'_, B>
impl<B> Ord for Cow<'_, B>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<'a> PartialOrd<&'a ByteStr> for Cow<'a, str>
impl<'a> PartialOrd<&'a ByteStr> for Cow<'a, str>
Source§impl<'a> PartialOrd<ByteString> for Cow<'_, str>
impl<'a> PartialOrd<ByteString> for Cow<'_, str>
1.0.0 · Source§impl<'a, B> PartialOrd for Cow<'a, B>
impl<'a, B> PartialOrd for Cow<'a, B>
§impl<C> RequestConnection for Cow<'_, C>
impl<C> RequestConnection for Cow<'_, C>
§type Buf = <C as RequestConnection>::Buf
type Buf = <C as RequestConnection>::Buf
§fn send_request_with_reply<R>(
&self,
bufs: &[IoSlice<'_>],
fds: Vec<OwnedFd>,
) -> Result<Cookie<'_, Cow<'_, C>, R>, ConnectionError>where
R: TryParse,
fn send_request_with_reply<R>(
&self,
bufs: &[IoSlice<'_>],
fds: Vec<OwnedFd>,
) -> Result<Cookie<'_, Cow<'_, C>, R>, ConnectionError>where
R: TryParse,
§fn send_trait_request_with_reply<R>(
&self,
request: R,
) -> Result<Cookie<'_, Cow<'_, C>, <R as ReplyRequest>::Reply>, ConnectionError>where
R: ReplyRequest,
fn send_trait_request_with_reply<R>(
&self,
request: R,
) -> Result<Cookie<'_, Cow<'_, C>, <R as ReplyRequest>::Reply>, ConnectionError>where
R: ReplyRequest,
§fn send_request_with_reply_with_fds<R>(
&self,
bufs: &[IoSlice<'_>],
fds: Vec<OwnedFd>,
) -> Result<CookieWithFds<'_, Cow<'_, C>, R>, ConnectionError>where
R: TryParseFd,
fn send_request_with_reply_with_fds<R>(
&self,
bufs: &[IoSlice<'_>],
fds: Vec<OwnedFd>,
) -> Result<CookieWithFds<'_, Cow<'_, C>, R>, ConnectionError>where
R: TryParseFd,
§fn send_trait_request_with_reply_with_fds<R>(
&self,
request: R,
) -> Result<CookieWithFds<'_, Cow<'_, C>, <R as ReplyFDsRequest>::Reply>, ConnectionError>where
R: ReplyFDsRequest,
fn send_trait_request_with_reply_with_fds<R>(
&self,
request: R,
) -> Result<CookieWithFds<'_, Cow<'_, C>, <R as ReplyFDsRequest>::Reply>, ConnectionError>where
R: ReplyFDsRequest,
§fn send_request_without_reply(
&self,
bufs: &[IoSlice<'_>],
fds: Vec<OwnedFd>,
) -> Result<VoidCookie<'_, Cow<'_, C>>, ConnectionError>
fn send_request_without_reply( &self, bufs: &[IoSlice<'_>], fds: Vec<OwnedFd>, ) -> Result<VoidCookie<'_, Cow<'_, C>>, ConnectionError>
§fn send_trait_request_without_reply<R>(
&self,
request: R,
) -> Result<VoidCookie<'_, Cow<'_, C>>, ConnectionError>where
R: VoidRequest,
fn send_trait_request_without_reply<R>(
&self,
request: R,
) -> Result<VoidCookie<'_, Cow<'_, C>>, ConnectionError>where
R: VoidRequest,
§fn discard_reply(&self, sequence: u64, kind: RequestKind, mode: DiscardMode)
fn discard_reply(&self, sequence: u64, kind: RequestKind, mode: DiscardMode)
§fn prefetch_extension_information(
&self,
extension_name: &'static str,
) -> Result<(), ConnectionError>
fn prefetch_extension_information( &self, extension_name: &'static str, ) -> Result<(), ConnectionError>
§fn extension_information(
&self,
extension_name: &'static str,
) -> Result<Option<ExtensionInformation>, ConnectionError>
fn extension_information( &self, extension_name: &'static str, ) -> Result<Option<ExtensionInformation>, ConnectionError>
§fn wait_for_reply_or_error(
&self,
sequence: u64,
) -> Result<<Cow<'_, C> as RequestConnection>::Buf, ReplyError>
fn wait_for_reply_or_error( &self, sequence: u64, ) -> Result<<Cow<'_, C> as RequestConnection>::Buf, ReplyError>
§fn wait_for_reply_or_raw_error(
&self,
sequence: u64,
) -> Result<ReplyOrError<<Cow<'_, C> as RequestConnection>::Buf>, ConnectionError>
fn wait_for_reply_or_raw_error( &self, sequence: u64, ) -> Result<ReplyOrError<<Cow<'_, C> as RequestConnection>::Buf>, ConnectionError>
§fn wait_for_reply(
&self,
sequence: u64,
) -> Result<Option<<Cow<'_, C> as RequestConnection>::Buf>, ConnectionError>
fn wait_for_reply( &self, sequence: u64, ) -> Result<Option<<Cow<'_, C> as RequestConnection>::Buf>, ConnectionError>
§fn wait_for_reply_with_fds(
&self,
sequence: u64,
) -> Result<(<Cow<'_, C> as RequestConnection>::Buf, Vec<OwnedFd>), ReplyError>
fn wait_for_reply_with_fds( &self, sequence: u64, ) -> Result<(<Cow<'_, C> as RequestConnection>::Buf, Vec<OwnedFd>), ReplyError>
§fn wait_for_reply_with_fds_raw(
&self,
sequence: u64,
) -> Result<ReplyOrError<(<Cow<'_, C> as RequestConnection>::Buf, Vec<OwnedFd>), <Cow<'_, C> as RequestConnection>::Buf>, ConnectionError>
fn wait_for_reply_with_fds_raw( &self, sequence: u64, ) -> Result<ReplyOrError<(<Cow<'_, C> as RequestConnection>::Buf, Vec<OwnedFd>), <Cow<'_, C> as RequestConnection>::Buf>, ConnectionError>
§fn check_for_error(&self, sequence: u64) -> Result<(), ReplyError>
fn check_for_error(&self, sequence: u64) -> Result<(), ReplyError>
§fn check_for_raw_error(
&self,
sequence: u64,
) -> Result<Option<<Cow<'_, C> as RequestConnection>::Buf>, ConnectionError>
fn check_for_raw_error( &self, sequence: u64, ) -> Result<Option<<Cow<'_, C> as RequestConnection>::Buf>, ConnectionError>
§fn prefetch_maximum_request_bytes(&self)
fn prefetch_maximum_request_bytes(&self)
§fn maximum_request_bytes(&self) -> usize
fn maximum_request_bytes(&self) -> usize
§fn parse_error(&self, error: &[u8]) -> Result<X11Error, ParseError>
fn parse_error(&self, error: &[u8]) -> Result<X11Error, ParseError>
§fn parse_event(&self, event: &[u8]) -> Result<Event, ParseError>
fn parse_event(&self, event: &[u8]) -> Result<Event, ParseError>
Source§impl<'a, T> Serialize for Cow<'a, T>
Available on crate features std
or alloc
only.
impl<'a, T> Serialize for Cow<'a, T>
std
or alloc
only.Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Source§impl<T> ToTokens for Cow<'_, T>
impl<T> ToTokens for Cow<'_, T>
Source§fn to_tokens(&self, tokens: &mut TokenStream)
fn to_tokens(&self, tokens: &mut TokenStream)
proc_macro_totokens
)Source§fn to_token_stream(&self) -> TokenStream
fn to_token_stream(&self) -> TokenStream
proc_macro_totokens
)Source§fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
proc_macro_totokens
)Source§impl<'a, T> ToTokens for Cow<'a, T>
impl<'a, T> ToTokens for Cow<'a, T>
Source§fn to_tokens(&self, tokens: &mut TokenStream)
fn to_tokens(&self, tokens: &mut TokenStream)
Source§fn to_token_stream(&self) -> TokenStream
fn to_token_stream(&self) -> TokenStream
Source§fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
§impl<'a, T> Writeable for Cow<'a, T>
impl<'a, T> Writeable for Cow<'a, T>
§fn write_to<W>(&self, sink: &mut W) -> Result<(), Error>
fn write_to<W>(&self, sink: &mut W) -> Result<(), Error>
write_to_parts
, and discards any
Part
annotations.§fn write_to_parts<W>(&self, sink: &mut W) -> Result<(), Error>where
W: PartsWrite + ?Sized,
fn write_to_parts<W>(&self, sink: &mut W) -> Result<(), Error>where
W: PartsWrite + ?Sized,
Part
annotations to the given sink. Errors from the
sink are bubbled up. The default implementation delegates to write_to
,
and doesn’t produce any Part
annotations.§fn writeable_length_hint(&self) -> LengthHint
fn writeable_length_hint(&self) -> LengthHint
§fn write_to_string(&self) -> Cow<'_, str>
fn write_to_string(&self) -> Cow<'_, str>
String
with the data from this Writeable
. Like ToString
,
but smaller and faster. Read more§fn writeable_cmp_bytes(&self, other: &[u8]) -> Ordering
fn writeable_cmp_bytes(&self, other: &[u8]) -> Ordering
Writeable
to the given bytes
without allocating a String to hold the Writeable
contents. Read more§impl<'a, T> Yokeable<'a> for Cow<'static, T>
Available on crate feature alloc
only.
impl<'a, T> Yokeable<'a> for Cow<'static, T>
alloc
only.§fn transform_owned(self) -> Cow<'a, T>
fn transform_owned(self) -> Cow<'a, T>
§unsafe fn make(from: Cow<'a, T>) -> Cow<'static, T>
unsafe fn make(from: Cow<'a, T>) -> Cow<'static, T>
Self<'a>
’s lifetime. Read more§fn transform_mut<F>(&'a mut self, f: F)
fn transform_mut<F>(&'a mut self, f: F)
self
between &'a mut Self<'static>
and &'a mut Self<'a>
,
and pass it to f
. Read moreimpl<T> DerefPure for Cow<'_, T>where
T: Clone,
impl DerefPure for Cow<'_, str>
no_global_oom_handling
only.